error VBA next without for

  • Thread starter Thread starter mohavv
  • Start date Start date
M

mohavv

Hi,

Have some code below which give me an Error: Next without for.
What Am I Doing Wrong??
Cheers,
Harold

Sub test2()

ScreenUpdating = False

Dim Dir As String
Dim Wbk As String
Dim Sht As String
Dim Num As String

For a = 5 To 8

Dir = Sheets("print").Range("B" & a).Value
Wbk = Sheets("print").Range("C" & a).Value
Sht = Sheets("print").Range("D" & a).Value
Num = Sheets("print").Range("E" & a).Value


If a > 7 Then
ChDir (Dir)
Workbooks.Open Filename:=Wbk, _
UpdateLinks:=3

With Sheets(Sht).PageSetup
.LeftFooter = "&8&Z&F - &A"
.RightFooter = "&8&D - &T & " & Num
End With
Sheets(Sht).PrintOut

Next a

End Sub
 
Hi,

Have some code below which give me an Error: Next without for.
What Am I Doing Wrong??
Cheers,
Harold

Sub test2()

ScreenUpdating = False

Dim Dir As String
Dim Wbk As String
Dim Sht As String
Dim Num As String

For a = 5 To 8

Dir = Sheets("print").Range("B" & a).Value
Wbk = Sheets("print").Range("C" & a).Value
Sht = Sheets("print").Range("D" & a).Value
Num = Sheets("print").Range("E" & a).Value


If a > 7 Then
ChDir (Dir)
Workbooks.Open Filename:=Wbk, _
UpdateLinks:=3

With Sheets(Sht).PageSetup
.LeftFooter = "&8&Z&F - &A"
.RightFooter = "&8&D - &T & " & Num
End With
Sheets(Sht).PrintOut

Next a

End Sub

You are missing the end if to terminate the:

If a > 7 then
...
...
With Sheets
...
...
End With
????? end if ?????
--ron
 

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

VB question 2
Macro to insert pictures in comments 8
Clear Range problem 2
Named Range maker code 9
Unique print macro question 3
Insert letter in cell 2
regular code module 4
Insert row and copy formulas 5

Back
Top