VBA ERROR

  • Thread starter Hamed parhizkar
  • Start date
H

Hamed parhizkar

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"

???
 
R

Rick Rothstein \(MVP - VB\)

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
 
J

Jason Lepack

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads

VBA ERROR 2
VBA IF QUESTION 6
Run Macro If Cell have "x" value 0
Page Breaks in VBA Q 6
Command Button 6
Print Code Help 5
Print two different areas on a worksheet 4
Change settings for print 1

Top