ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   VBA ERROR (https://www.excelbanter.com/excel-programming/409065-vba-error.html)

Hamed parhizkar

VBA ERROR
 
I am running an 16 if functions similar to this below:

If Range("C28") 0 Then
Range("A23:D34").Select
ActiveSheet.PageSetup.PrintArea = "$A$23:$D$34"
ActiveWindow.SelectedSheets.PrintOut Copies:=1, Collate:=True
End If

When I try to run it I get an error saying "Block If without End if"

My very last function ends with:

End If

End Sub

But if I take the end sub out I get an error that reads" Expected end Sub"

???

Rick Rothstein \(MVP - VB\)[_1677_]

VBA ERROR
 
ALL of your If-Then blocks (the one's where nothing follows the Then on the
same line) MUST have a matching End If statement... every one of them. And,
if the If-Then blocks are nested, the End If statements must be located
correctly. If you post that part of your code dealing just with the 16
If-Then calls (and if it isn't too long to follow), I'm sure someone here
will restructure it for you.

Rick


"Hamed parhizkar" wrote in
message ...
I am running an 16 if functions similar to this below:

If Range("C28") 0 Then
Range("A23:D34").Select
ActiveSheet.PageSetup.PrintArea = "$A$23:$D$34"
ActiveWindow.SelectedSheets.PrintOut Copies:=1, Collate:=True
End If

When I try to run it I get an error saying "Block If without End if"

My very last function ends with:

End If

End Sub

But if I take the end sub out I get an error that reads" Expected end Sub"

???



Jason Lepack

VBA ERROR
 
When I try to run it I get an error saying "Block If without End if"

That means that you're missing an End If somewhere.

My very last function ends with:

End If

End Sub

But if I take the end sub out I get an error that reads" Expected end Sub"


When VBA compiles it looks at the SUB, END SUB combos take make sure
that it finds one before checking the IF, END IF. When you remove the
END SUB, it causes VBA to throw that error.

Cheers,
Jason Lepack


All times are GMT +1. The time now is 07:14 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com