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

Hi, I have a workbook with two worksheets; which are mainly static,
except for sheet1C12 which gets values from sheet2A2:A30 (or better yet
till it hits a blank). Now what I want to do is create a loop that will
assing the value of Sheet2A2 into Sheet1C12 (then print); then
increment and assing the value of Sheet2A3 into Sheet1C12 (then print
again) and so on till a last predefined sheet2Ax or till it hits a
blank, I have been reading but cannot find anything similar. Here's
what I have so far

Sub PrintMacro()

Worksheets("Sheet1").Range("C12").Value =
Worksheets("Sheet2").Range("A2").Value
ActiveSheet.PrintPreview

End Sub

I know I have to change ActiveSheet.PrintPreview to
ActiveSheet.PrintOut, in order to print, but what I need to know is a
way to increment A2 into A3, A4.... ect.
Is there a for loop in VBA?
Thanks in advance

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,123
Default Excel print loop

Try this for A2 to A10

Sub PrintMacro()
Dim I As Integer
For I = 2 To 10
Worksheets("Sheet1").Range("C12").Value = _
Worksheets("Sheet2").Range("A" & I).Value
ActiveSheet.PrintPreview
Next I
End Sub



--
Regards Ron de Bruin
http://www.rondebruin.nl


wrote in message oups.com...
Hi, I have a workbook with two worksheets; which are mainly static,
except for sheet1C12 which gets values from sheet2A2:A30 (or better yet
till it hits a blank). Now what I want to do is create a loop that will
assing the value of Sheet2A2 into Sheet1C12 (then print); then
increment and assing the value of Sheet2A3 into Sheet1C12 (then print
again) and so on till a last predefined sheet2Ax or till it hits a
blank, I have been reading but cannot find anything similar. Here's
what I have so far

Sub PrintMacro()

Worksheets("Sheet1").Range("C12").Value =
Worksheets("Sheet2").Range("A2").Value
ActiveSheet.PrintPreview

End Sub

I know I have to change ActiveSheet.PrintPreview to
ActiveSheet.PrintOut, in order to print, but what I need to know is a
way to increment A2 into A3, A4.... ect.
Is there a for loop in VBA?
Thanks in advance

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2
Default Excel print loop

Thanks, this works like a charm, now I need to find find a way to do it
until it hits a blank cell; I think that will be a while loop, or maybe
an if clause.
Thanks

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,123
Default Excel print loop

You can use this

Sub PrintMacro2()
Dim cell As Range
For Each cell In Sheets("Sheet2").Range("A2:A" & Rows.Count) _
.SpecialCells(xlCellTypeConstants)
Worksheets("Sheet1").Range("C12").Value = cell.Value
ActiveSheet.PrintPreview
Next cell
End Sub




--
Regards Ron de Bruin
http://www.rondebruin.nl


wrote in message ups.com...
Thanks, this works like a charm, now I need to find find a way to do it
until it hits a blank cell; I think that will be a while loop, or maybe
an if clause.
Thanks

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
First page of Excel sheerepeats in print layout or print preview philfrotonda Excel Discussion (Misc queries) 1 July 12th 07 09:28 PM
Macro for Print Loop within Excel Browner[_4_] Excel Programming 3 May 18th 06 01:22 PM
Advancing outer Loop Based on criteria of inner loop ExcelMonkey Excel Programming 1 August 15th 05 05:23 PM
How do you Print with a loop? rohrl77 Excel Programming 3 June 14th 05 09:10 AM
Why does macro speed slow after Excel Print or Print Preview? Larry A[_3_] Excel Programming 6 May 16th 05 11:22 AM


All times are GMT +1. The time now is 12:04 PM.

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

About Us

"It's about Microsoft Excel"