Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 245
Default Stepping through v. running code

Greetings,
When i step through this it works perfectly. However when i run it it only
returns the first "i" for each any thoughts?

Sub PrintEmOut()
Dim MyRange As Range
Dim WS As Worksheet
Dim Lastrow As Long
Dim i As Variant

Set WS = ActiveWorkbook.Worksheets(2)
Lastrow = WS.Cells(Cells.Rows.Count, "B").End(xlUp).Row
Set MyRange = WS.Range("B2:B" & Lastrow)

For Each i In MyRange
With Worksheets(1)
.Label1.Caption = i
.Label2.Caption = i.Offset(0, 13).Value
.Label3.Caption = i.Offset(0, 11).Value
.PrintPreview
.Label1.Caption = ""
.Label2.Caption = ""
.Label3.Caption = ""
End With
Next
End Sub

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 9,101
Default Stepping through v. running code

If you have more than one workbook open make sure you have the one you are
modifying active before steopping through code. I also added activeworkbook
to the with statement.

from
For Each i In MyRange
With ActiveWorkbook.Worksheets(1)
..
..
..
End With
Next

to
For Each i In MyRange
With Worksheets(1)
..
..
..
End With
Next

"Office_Novice" wrote:

Greetings,
When i step through this it works perfectly. However when i run it it only
returns the first "i" for each any thoughts?

Sub PrintEmOut()
Dim MyRange As Range
Dim WS As Worksheet
Dim Lastrow As Long
Dim i As Variant

Set WS = ActiveWorkbook.Worksheets(2)
Lastrow = WS.Cells(Cells.Rows.Count, "B").End(xlUp).Row
Set MyRange = WS.Range("B2:B" & Lastrow)

For Each i In MyRange
With Worksheets(1)
.Label1.Caption = i
.Label2.Caption = i.Offset(0, 13).Value
.Label3.Caption = i.Offset(0, 11).Value
.PrintPreview
.Label1.Caption = ""
.Label2.Caption = ""
.Label3.Caption = ""
End With
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
Stepping through gives different result than running Gregg Roberts Excel Programming 10 September 22nd 06 08:42 PM
BreakLinks method works when Stepping Through but not when Running! WhytheQ Excel Programming 2 September 19th 06 02:36 PM
Error Message When running code but not stepping through it. Jared Excel Programming 4 November 16th 04 07:09 PM
VBA Code works by stepping through, not by running JbL Excel Programming 7 November 4th 04 02:49 PM
Stepping through code gives different results than running it! Simon White Excel Programming 2 November 13th 03 09:44 PM


All times are GMT +1. The time now is 10:00 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"