Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8724097
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T07:45:35+00:00 2026-06-13T07:45:35+00:00

Pls help me modify this code but I would like to keep it 90%

  • 0

Pls help me modify this code but I would like to keep it 90% the same.

I want to delete the rows that does not contain the array items. So my program deletes rows with a, b in cell. How can I modify the below code so that it erases the other a, b to remain in exec.

myArr = Array("a","b")
For I = LBound(myArr) To UBound(myArr)

    'Sheet with the data, you can also use Sheets("MySheet")
    With ActiveSheet

        'Firstly, remove the AutoFilter
        .AutoFilterMode = False

        'Apply the filter
        .Range("E1:E" & .Rows.Count).AutoFilter Field:=1, Criteria1:=myArr(I)

        Set rng = Nothing
        With .AutoFilter.Range
            On Error Resume Next
            Set rng = .Offset(1, 0).Resize(.Rows.Count - 1, 1) _
                      .SpecialCells(xlCellTypeVisible)
            On Error GoTo 0
            If Not rng Is Nothing Then rng.EntireRow.Delete
        End With

        'Remove the AutoFilter
        .AutoFilterMode = False
    End With
Next I
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-13T07:45:36+00:00Added an answer on June 13, 2026 at 7:45 am

    This works for me… I have commented the code so you should not have a problem understanding it…

    Option Explicit
    
    Dim myArr
    
    Sub Sample()
        Dim ws As Worksheet
        Dim Lrow As Long, i As Long
        Dim rRange As Range, delRange As Range
    
        myArr = Array("a", "b", "c")
    
        Set ws = ThisWorkbook.Sheets("MySheet")
    
        With ws
            '~~> Get last row of Sheet
            Lrow = .Range("A" & .Rows.Count).End(xlUp).Row
    
            For i = 2 To Lrow
                If Not DoesExists(.Range("A" & i).Value) Then
                    If delRange Is Nothing Then
                        Set delRange = .Range("A" & i)
                    Else
                        Set delRange = Union(delRange, .Range("A" & i))
                    End If
                End If
            Next i
    
            If Not delRange Is Nothing Then delRange.EntireRow.Delete
        End With
    End Sub
    
    Function DoesExists(clVal As Variant) As Boolean
        Dim j As Long
    
        For j = LBound(myArr) To UBound(myArr)
            If clVal = myArr(j) Then
                DoesExists = True: Exit For
            End If
        Next j
    End Function
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

This code shows syntax error in the parameter declaration.. Pls help me to solve
I am trying to create a slider like this example. pls anyone help me.
pls help me. how can I split this String value? my code below wont
I want to create a XML file in csharp like the below format pls
can't understand why this image resizing not working pls help //updating article function updateArticle(){
I want to send data from my Windows form to client wep page(.aspx).Pls help
I am still doing something wrong. Could somebody pls help me? I want to
I am too tired to figure this out, so pls help. I have an
Pls help me with this: The AppDelegate has an argument called user: @interface AppDelegate
can anyone pls help me convert this to vb.net for each (DictionaryEntry<String, Int64> entry

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.