A Microsoft Excel forum. ExcelBanter

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

Go Back   Home » ExcelBanter forum » Excel Newsgroups » Excel Discussion (Misc queries)
Site Map Home Register Authors List Search Today's Posts Mark Forums Read Web Partners

error VBA next without for



 
 
Thread Tools Display Modes
  #1  
Old December 12th 07, 01:02 AM posted to microsoft.public.excel.misc
mohavv
external usenet poster
 
Posts: 68
Default error VBA next without for

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
Ads
  #2  
Old December 12th 07, 01:11 AM posted to microsoft.public.excel.misc
Ron Rosenfeld
external usenet poster
 
Posts: 5,651
Default error VBA next without for

On Tue, 11 Dec 2007 16:02:43 -0800 (PST), mohavv > wrote:

>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
 




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Error: "Excel encountered an error and had to remove some formatti Carl Excel Discussion (Misc queries) 0 September 18th 06 06:39 PM
Counting instances of found text (Excel error? Or user error?) S Davis Excel Worksheet Functions 5 September 12th 06 04:52 PM
I have Error 1919 Error Configuring ODBC dataSource Database Texanna1 Excel Discussion (Misc queries) 1 September 12th 06 06:35 AM
Excel 2003 Macro Error - Runtime error 1004 Cow Excel Discussion (Misc queries) 2 June 7th 05 01:40 PM


All times are GMT +1. The time now is 09:42 AM.


Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2014, Jelsoft Enterprises Ltd.
Copyright 2004-2014 ExcelBanter.
The comments are property of their posters.