Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 846
Default Problem with loop

I'm new with loops and I can not seem to exit this loop. The loop works in
notifying the user there is no more data (by way of msgbox). But when I click
Okay on the box, it just stays there. So I'm thinking the loop is not exiting
properly. Can you help me exit this loop. Thanks.

Sub printfromqueue()
Dim usrid As String
Dim sh As Worksheet
Dim rng As Range
Dim bk As Workbook
Dim cell As Range
usrid = Environ("Username")
Set sh = Workbooks(usrid & ".xls").Worksheets("Sheet1")

Set rng = sh.Range(sh.Cells(1, 1), sh.Cells(1, 1).End(xlDown))

For Each cell In rng
If cell.Value < "" Then
Set bk = Workbooks.Open(cell.Value)
finalizequeue 'print macro
bk.Close savechanges:=False
Else: MsgBox ("no more data"), vbOKOnly
End If
Next
End Sub
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default Problem with loop

Actually, you should never process a cell that is empty. So assume there is
a null string in some of your cells.

Sub printfromqueue()
Dim usrid As String
Dim sh As Worksheet
Dim rng As Range
Dim bk As Workbook
Dim cell As Range
usrid = Environ("Username")
Set sh = Workbooks(usrid & ".xls").Worksheets("Sheet1")

Set rng = sh.Range(sh.Cells(1, 1), sh.Cells(1, 1).End(xlDown))

For Each cell In rng
If cell.Value < "" Then
Set bk = Workbooks.Open(cell.Value)
finalizequeue 'print macro
bk.Close savechanges:=False
Else
MsgBox ("no more data"), vbOKOnly
exit For
End If
Next
End Sub

--
Regards,
Tom Ogilvy

"Brad" wrote in message
...
I'm new with loops and I can not seem to exit this loop. The loop works in
notifying the user there is no more data (by way of msgbox). But when I

click
Okay on the box, it just stays there. So I'm thinking the loop is not

exiting
properly. Can you help me exit this loop. Thanks.

Sub printfromqueue()
Dim usrid As String
Dim sh As Worksheet
Dim rng As Range
Dim bk As Workbook
Dim cell As Range
usrid = Environ("Username")
Set sh = Workbooks(usrid & ".xls").Worksheets("Sheet1")

Set rng = sh.Range(sh.Cells(1, 1), sh.Cells(1, 1).End(xlDown))

For Each cell In rng
If cell.Value < "" Then
Set bk = Workbooks.Open(cell.Value)
finalizequeue 'print macro
bk.Close savechanges:=False
Else: MsgBox ("no more data"), vbOKOnly
End If
Next
End Sub



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 846
Default Problem with loop

Thanks Tom, that did the trick!

"Tom Ogilvy" wrote:

Actually, you should never process a cell that is empty. So assume there is
a null string in some of your cells.

Sub printfromqueue()
Dim usrid As String
Dim sh As Worksheet
Dim rng As Range
Dim bk As Workbook
Dim cell As Range
usrid = Environ("Username")
Set sh = Workbooks(usrid & ".xls").Worksheets("Sheet1")

Set rng = sh.Range(sh.Cells(1, 1), sh.Cells(1, 1).End(xlDown))

For Each cell In rng
If cell.Value < "" Then
Set bk = Workbooks.Open(cell.Value)
finalizequeue 'print macro
bk.Close savechanges:=False
Else
MsgBox ("no more data"), vbOKOnly
exit For
End If
Next
End Sub

--
Regards,
Tom Ogilvy

"Brad" wrote in message
...
I'm new with loops and I can not seem to exit this loop. The loop works in
notifying the user there is no more data (by way of msgbox). But when I

click
Okay on the box, it just stays there. So I'm thinking the loop is not

exiting
properly. Can you help me exit this loop. Thanks.

Sub printfromqueue()
Dim usrid As String
Dim sh As Worksheet
Dim rng As Range
Dim bk As Workbook
Dim cell As Range
usrid = Environ("Username")
Set sh = Workbooks(usrid & ".xls").Worksheets("Sheet1")

Set rng = sh.Range(sh.Cells(1, 1), sh.Cells(1, 1).End(xlDown))

For Each cell In rng
If cell.Value < "" Then
Set bk = Workbooks.Open(cell.Value)
finalizequeue 'print macro
bk.Close savechanges:=False
Else: MsgBox ("no more data"), vbOKOnly
End If
Next
End Sub




Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
do while loop problem April Excel Discussion (Misc queries) 4 October 18th 09 07:51 PM
Problem with Do Loop and If aehan Excel Programming 7 April 8th 05 01:01 AM
For Next loop problem Jo[_6_] Excel Programming 2 June 26th 04 12:41 AM
Loop Problem Todd Huttenstine Excel Programming 10 April 12th 04 06:15 PM
For..Next loop problem Dwaine Horton Excel Programming 1 February 18th 04 12:12 AM


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

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

About Us

"It's about Microsoft Excel"