Filter and delete criteria with loop

jaik22

Board Regular
Joined
Sep 23, 2016
Messages
102
Code:
Sub GatherInfoHimchanLooping()


Dim exclude As String
Dim endrow As String: endrow = Sheets("Info").Range("E100").End(xlUp).Row
Dim Finalrow As String: Finalrow = Sheets("Info").Range("I100").End(xlUp).Row



For i = 24 To endrow
    exclude = Cells(i, 5).Value
        Sheets("Data").Select
           LastRowColumnA = Cells(Rows.Count, 1).End(xlUp).Row
            ActiveSheet.Range("$A$1:$O$" & LastRowColumnA ).AutoFilter Field:=2, Criteria1:= _
             exclude, Operator:=xlAnd
                 On Error Resume Next
                 Range("O2:O" & LastRowColumnA ).SpecialCells(xlCellTypeVisible).Value = "x"
                     'Selection.Value = "x"
                        ActiveSheet.ShowAllData
        Sheets("Info").Select

Next i

End Sub

Hi guys, this loop is trying to see info tab and anything matches in I column in column 2 in data tab, I will mark x in column O.
However, I am having a problem with my loop. seems like my loop is ignoring variables(endrow, Finalrow) while looping.
Also instead of making column O to mark x, how can I delete the filtered criteria right away?

Any advice helps!

Thank you
 

Excel Facts

Easy bullets in Excel
If you have a numeric keypad, press Alt+7 on numeric keypad to type a bullet in Excel.
Code:
Dim endrow As String


try making endrow and FinalRow as Long instead of string
because
i = 24 to "50" doesnt work
it needs to be 24 to 50

also you set finalrow but its never used in the code
what is it meant to do that is different to endrow?
 
Last edited:
Upvote 0
Code:
[color=darkblue]Sub[/color] GatherInfoHimchanLooping()
    
    [color=darkblue]Dim[/color] LastRowColumnA [color=darkblue]As[/color] [color=darkblue]Long[/color]
    LastRowColumnA = Sheets("Data").Cells(Rows.Count, 1).End(xlUp).Row
    
    [color=darkblue]For[/color] i = 24 [color=darkblue]To[/color] Sheets("Info").Range("E100").End(xlUp).Row
        Sheets("Data").Range("A1:O" & LastRowColumnA).AutoFilter Field:=2, Criteria1:=Sheets("Info").Cells(i, 5).Value
        [color=darkblue]On[/color] [color=darkblue]Error[/color] [color=darkblue]Resume[/color] [color=darkblue]Next[/color]
        Sheets("Data").Range("O2:O" & LastRowColumnA).SpecialCells(xlCellTypeVisible).EntireRow.Delete
        [color=darkblue]On[/color] [color=darkblue]Error[/color] [color=darkblue]GoTo[/color] 0
    [color=darkblue]Next[/color] i
    
    Sheets("Data").ShowAllData
    
[color=darkblue]End[/color] [color=darkblue]Sub[/color]
 
Upvote 0

Forum statistics

Threads
1,215,730
Messages
6,126,528
Members
449,316
Latest member
sravya

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top