LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 55
Default For Next Looping (custom variables)

So, if I understand you correctly, you would like a macro that allows
you to define the order of printing of the sheets and then prints them
in that order. If so, here's what you can do:

1. This code will list all the sheets and ask you to input a print
order number in the cell to the right of that sheet name:

Sub ListSheets()

Dim intSht As Integer

Application.ScreenUpdating = False

' Create new sheet
On Error Resume Next
Sheets("Sheet List").Activate
If Err.Number < 0 Then
Sheets.Add
ActiveSheet.Name = "Sheet List"
Else
Sheets("Sheet List").Cells.Delete
End If
Err.Clear
On Error GoTo 0

' Create headings
Range("A1").Value = "Sheet Name"
Range("B1").Value = "Print Order"

' List sheets (except Sheet List)
intSht = 2
For Each sht In Sheets
If sht.Name < "Sheet List" Then
Range("A" & intSht).Value = sht.Name
intSht = intSht + 1
End If
Next sht

ActiveSheet.Cells.EntireColumn.AutoFit

Application.ScreenUpdating = True

End Sub

2. Once you have determined the print order and typed it in, run this
macro.

Sub PrintInOrder()

Application.ScreenUpdating = False

' Make sure the list is there.
On Error Resume Next
Sheets("Sheet List").Activate
If Err.Number < 0 Then
MsgBox ("Please run the ListSheets subroutine first.")
Exit Sub
End If
' Make sure the print order is input.
If WorksheetFunction.CountA(Range("B:B")) <
WorksheetFunction.CountA(Range("A:A")) Then
MsgBox ("You must input all print orders. Please do so and
re-run this macro.")
Exit Sub
End If
On Error GoTo 0

Range("A:B").Sort Key1:=Range("B:B"), Order1:=xlAscending,
Header:=xlYes

For x = 2 To ActiveSheet.UsedRange.SpecialCells(xlLastCell).Row
Sheets(Range("A" & x).Value).Print
Next x

Application.DisplayAlerts = False
Sheets("Sheet List").Delete
Application.DisplayAlerts = True

Application.ScreenUpdating = True

End Sub

If you have any problems, please let me know.

Mark

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
 
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
Looping Through Variables NigelShaw Excel Discussion (Misc queries) 6 October 26th 08 10:42 PM
Looping Maggie[_6_] Excel Discussion (Misc queries) 6 October 2nd 08 09:14 PM
Not at all clear on use of variables and/or object variables JMay-Rke Excel Discussion (Misc queries) 11 July 4th 08 06:36 PM
Not Looping Roger Excel Discussion (Misc queries) 0 February 26th 08 05:18 PM
Looping David T Excel Discussion (Misc queries) 2 August 30th 06 10:51 PM


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