End With Without With Compile error

soultrain000

New Member
Joined
Dec 8, 2010
Messages
37
Hi Fellows,

I am getting an "End With without With" compile error.
Can someone help please?


Code:
Sheets("Setup").Select
If (ActiveSheet.AutoFilterMode) Then ActiveSheet.AutoFilterMode = False
    Range("I4").Select
    xRow = Range("I4").End(xlDown).Row
        Range("F4:BU" & xRow).Select
        Selection.Name = "rawdata"
        Range("N3").Select
      x = ActiveCell.Address
 
Do Until ActiveCell.Value = ""
prop = ActiveCell
xCol = ActiveCell.Column
Sheets(prop).Select
sRow = (Range("F9").End(xlDown).Row) + 1
eRow = sRow + 2
    'Range("A" & eRow & ":H10000").Select
    'Selection.ClearContents
i = 9
    
    Sheets("Rawact").Select
     If (ActiveSheet.AutoFilterMode) Then ActiveSheet.AutoFilterMode = False
     Rows("2:10000").Select
     Selection.ClearContents
     
    Sheets("Setup").Select
    With Range("rawdata")
        .AutoFilter Field:=i, Criteria1:="Yes"
        xxRow = (Range("I4").End(xlDown).Row)
        Worksheets("Setup").Range("F4:M" & xxRow).Copy
        Sheets("Rawact").Range("A2").PasteSpecial _
               Paste:=xlValues, Operation:=xlNone, SkipBlanks:=False, Transpose:=False
        
        Sheets("Rawact").Select
        raaRow = (Range("D2").End(xlDown).Row)
        Range("I2").Formula = "=IF(ISNA(VLOOKUP(""?????""&A2,INDIRECT(""" & prop & "!A1:A10000""),1,FALSE)),1,0)"
        Range("I2").Copy Range("I2:I" & raaRow)
 Application.Calculation = xlCalculationAutomatic
 
 If (ActiveSheet.AutoFilterMode) Then ActiveSheet.AutoFilterMode = False
   If Range("I1").Value > 0 Then
    
    
    With Range("A2:I" & raaRow)
        .AutoFilter Field:=9, Criteria1:="1"
        cRow = Range("D2").End(xlDown).Row
        Worksheets("Rawact").Range("A2:H" & cRow).Copy
        Sheets(prop).Select
Columns("A:C").Select
    Selection.EntireColumn.Hidden = False
firstrow = Columns(1).Find("*", Cells(2, 1), SearchDirection:=xlNext).Row
lastrow = Range("A" & firstrow).End(xlDown).Row
Range("A" & lastrow + 1).Select
End With
        
        Sheets(prop).Range("A" & lastrow + 1).PasteSpecial _
               Paste:=xlValues, Operation:=xlNone, SkipBlanks:=False, Transpose:=False
        
        finalrow = Range("A" & firstrow).End(xlDown).Row
 
 

 
 For i = firstrow To finalrow
    Cells(i, "A").Value = Cells(1, "A").Value & Cells(i, "B").Value & Cells(i, "C").Value & Cells(i, "D").Value & Cells(i, "E").Value
Next i
 
 
    
Sheets("Setup").Select
If (ActiveSheet.AutoFilterMode) Then ActiveSheet.AutoFilterMode = False

ActiveCell.Offset(0, 1).Select
x = ActiveCell
i = i + 1
End With

Loop
   
Call Protect
End Sub
 

Excel Facts

Difference between two dates
Secret function! Use =DATEDIF(A2,B2,"Y")&" years"&=DATEDIF(A2,B2,"YM")&" months"&=DATEDIF(A2,B2,"MD")&" days"
You're missing an End If termination for this line


Code:
If Range("I1").Value > 0 Then
There may be other stuff like that, it's hard to read as it's not indented consistently.
 
Upvote 0
Proper indentation of code will help identify these problems

You were missing an END IF (highlighted in RED)

Rich (BB code):
Sub test()
Sheets("Setup").Select
If (ActiveSheet.AutoFilterMode) Then ActiveSheet.AutoFilterMode = False
Range("I4").Select
xRow = Range("I4").End(xlDown).Row
Range("F4:BU" & xRow).Select
Selection.Name = "rawdata"
Range("N3").Select
x = ActiveCell.Address
Do Until ActiveCell.Value = ""
    prop = ActiveCell
    xCol = ActiveCell.Column
    Sheets(prop).Select
    sRow = (Range("F9").End(xlDown).Row) + 1
    eRow = sRow + 2
    'Range("A" & eRow & ":H10000").Select
    'Selection.ClearContents
    i = 9
 
    Sheets("Rawact").Select
    If (ActiveSheet.AutoFilterMode) Then ActiveSheet.AutoFilterMode = False
    Rows("2:10000").Select
    Selection.ClearContents
 
    Sheets("Setup").Select
    With Range("rawdata")
        .AutoFilter Field:=i, Criteria1:="Yes"
        xxRow = (Range("I4").End(xlDown).Row)
        Worksheets("Setup").Range("F4:M" & xxRow).Copy
        Sheets("Rawact").Range("A2").PasteSpecial _
        Paste:=xlValues, Operation:=xlNone, SkipBlanks:=False, Transpose:=False
 
        Sheets("Rawact").Select
        raaRow = (Range("D2").End(xlDown).Row)
        Range("I2").Formula = "=IF(ISNA(VLOOKUP(""?????""&A2,INDIRECT(""" & prop & "!A1:A10000""),1,FALSE)),1,0)"
        Range("I2").Copy Range("I2:I" & raaRow)
        Application.Calculation = xlCalculationAutomatic
        If (ActiveSheet.AutoFilterMode) Then ActiveSheet.AutoFilterMode = False
        If Range("I1").Value > 0 Then
            With Range("A2:I" & raaRow)
                .AutoFilter Field:=9, Criteria1:="1"
                cRow = Range("D2").End(xlDown).Row
                Worksheets("Rawact").Range("A2:H" & cRow).Copy
                Sheets(prop).Select
                Columns("A:C").Select
                Selection.EntireColumn.Hidden = False
                firstrow = Columns(1).Find("*", Cells(2, 1), SearchDirection:=xlNext).Row
                lastrow = Range("A" & firstrow).End(xlDown).Row
                Range("A" & lastrow + 1).Select
           End With
       End If
       Sheets(prop).Range("A" & lastrow + 1).PasteSpecial _
              Paste:=xlValues, Operation:=xlNone, SkipBlanks:=False, Transpose:=False
 
       finalrow = Range("A" & firstrow).End(xlDown).Row
 
 
 
        For i = firstrow To finalrow
            Cells(i, "A").Value = Cells(1, "A").Value & Cells(i, "B").Value & Cells(i, "C").Value & Cells(i, "D").Value & Cells(i, "E").Value
        Next i
 
        Sheets("Setup").Select
        If (ActiveSheet.AutoFilterMode) Then ActiveSheet.AutoFilterMode = False
        ActiveCell.Offset(0, 1).Select
        x = ActiveCell
        i = i + 1
    End With
Loop
 
Call Protect
End Sub

Hope that helps.
 
Upvote 0
You need to indent your code properly so you can see the structure.

You have: If Range("I1").Value > 0 Then

with no corresponding End IF.

The With | End With pairs are matched but, because of the missing End If, VBA is getting confused. Not sure where the End If needs to go.

Regards
 
Upvote 0

Forum statistics

Threads
1,222,058
Messages
6,163,650
Members
451,852
Latest member
adamkhelil

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