Next without for? Weird error

Johnny C

Well-known Member
Joined
Nov 7, 2006
Messages
1,069
Office Version
  1. 365
Platform
  1. Windows
Hi.
This is my code. When it runs I get the error 'Compile error, next without for'.
VBA Code:
For Each c In wksControl.Range("OpSheets")
    strShtName = c.Value
    strYesNo = c.Offset(0, 2).Value
    If strYesNo = "Yes" Then
        IntLastRowCurr = Sheets(strShtName).Cells(Sheets(strShtName).Rows.Count, "A").End(xlUp).Row
        IntLastRowHist = Sheets(strShtName).Cells(Sheets(strShtName).Rows.Count, "I").End(xlUp).Row
        c.Offset(0, 5) = IntLastRowCurr
        strCrit1 = ""
        strCrit2 = ""
        strOp = ""
        Set sht = ActiveSheet
        ActiveWorkbook.Sheets(strShtName).Activate
        On Error Resume Next
        If ActiveSheet.AutoFilter.Filters.Item(9).On Then
             If Err.Number = 0 Then
                On Error GoTo 0
                boolFilters = True
                strCrit1 = ActiveSheet.AutoFilter.Filters.Item(9).Criteria1
                If ActiveSheet.AutoFilter.Filters.Item(9).Operator Then
                    strOp = ActiveSheet.AutoFilter.Filters.Item(9).Operator
                    strCrit2 = ActiveSheet.AutoFilter.Filters.Item(9).Criteria2
                End If
            End If
            On Error GoTo 0
        End If
  
        If boolFilters Then ActiveSheet.Range(Cells(4, 1), Cells(4, IntLastRowHist)).AutoFilter Field:=9
'
        
        ActiveSheet.Range(Cells(IntLastRowCurr, 2), Cells(IntLastRowHist, 9)).Copy
        ActiveSheet.Range(Cells(IntLastRowCurr + 1, 2), Cells(IntLastRowHist + 1, 9)).PasteSpecial Paste:=xlPasteValues
        
        If boolFilters Then
            If strCrit1 <> "" Then ActiveSheet.Range(Cells(4, 1), Cells(4, IntLastRowHist)).AutoFilter Field:=9, Criteria1:=strCrit1
            If strCrit2 <> "" Then ActiveSheet.Range(Cells(4, 1), Cells(4, IntLastRowHist)).AutoFilter Field:=9, Criteria1:=strCrit1, Operator:=strOp, Criteria2:=strCrit2
        End
        boolFilters = False
    End If

Next c
There is 1 for with a matching next and an 'on error resume next' . It was working fine last night. What am I not seeing?
 

Excel Facts

Move date out one month or year
Use =EDATE(A2,1) for one month later. Use EDATE(A2,12) for one year later.
You've got End not End If near the bottom.
 
Upvote 0
Solution
cheers (as always!) Rory. You'll be glad when I chuck my Excel hat in
 
Upvote 0

Forum statistics

Threads
1,215,063
Messages
6,122,930
Members
449,094
Latest member
teemeren

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