Do until with loop with a filter

Fean1976

New Member
Joined
Nov 14, 2016
Messages
2
Hi

It been a while that i have touched vba.

I am getting a compile error do without loop? But there is a do in the script. Its driving me nuts.


VBA Code:
Sub FilterEnt_IC()

Dim WbMacro As Workbook
Dim wb As Workbook
Dim strFilename As String
Dim iRow As Integer
Dim Ent As String
Set WbMacro = ThisWorkbook
iRow = 1

Application.ScreenUpdating = False

Do Until wbMacro.Sheets("Macro").Cells(iRow, 1) = ""
    'Ent = iRow
  
   'First 171500
    With wbMacro.Sheets("Data")
          .AutoFilterMode = False
            With .Range("A1:R1")
                .AutoFilter
                .AutoFilter Field:=2, Criteria1:="41100"
                .AutoFilter Field:=3, Criteria1:="175100"
                .AutoFilter Field:=4, Criteria1:="=0", Operator:=xlOr, Criteria2:="="
                .AutoFilter Field:=17, Criteria1:="=B001", Operator:=xlOr, Criteria2:="=L009"
            End With
        
        wbMacro.Sheets("Data").AutoFilter.Range.Copy
                
        wbMacro.Sheets("171500").Range("A" & Rows.Count).End(xlUp).Offset(1).PasteSpecial (xlPasteValues)
        
    
    iRow = iRow + 1
    
 Loop
    
End Sub
 

Excel Facts

How can you automate Excel?
Press Alt+F11 from Windows Excel to open the Visual Basic for Applications (VBA) editor.
Welcome to the Board!

I don't think the problem is with the loop part (Excel often show this "red herring" error message").
Rather, the issue is inside of the loop.
You have two "With" statements, but only one "End With".
Every "With" needs and "End With".
 
Upvote 0
Solution
Welcome to the Board!

I don't think the problem is with the loop part (Excel often show this "red herring" error message").
Rather, the issue is inside of the loop.
You have two "With" statements, but only one "End With".
Every "With" needs and "End With".
My goodness, i need some extra WD40 on my fingers and my brain. Sorry, that's such a no brainer, I guess i am getting too old for this;)
Thanks for the help!
 
Upvote 0
You are welcome.

No worries!
That error message can be a little misleading and lead you down the wrong path.
 
Upvote 0

Forum statistics

Threads
1,215,521
Messages
6,125,307
Members
449,218
Latest member
Excel Master

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