Here's the deal: I have three sheets in my workbook "New Rates
Calculator.xls" named "Home Delivery", "express", and "ground".
I have created a userform with three checkboxes for "Home delivery",
"Express", and "Ground". Now, I want the user to be able to check
these boxes (one at a time or all three if need be) and then have the
command button combine the selected sheets into a print preview. This
question includes how do I add to an array of sheets.
I am not a beginner and have scoured the newsgroups for a solution but
just can't seem to figure this out. Any help is greatly appreciated.
I think you can use it
Add a userform to your workbook with one listbox and one button
in the properties of the listbox set multiselect to 1
Place this code in the userform module
when you open the userform the listbox have all the sheets in them
Select the sheets you want and press the button to print
Private Sub CommandButton1_Click()
Dim arr() As String
Dim N As Integer
N = 0
For i = 0 To ListBox1.ListCount - 1
If ListBox1.Selected(i) = True Then
N = N + 1
ReDim Preserve arr(1 To N)
arr(N) = ListBox1.List(i)
End If
Next i
If N = 0 Then
MsgBox "You must select at least one Sheet"
Exit Sub
End If
ThisWorkbook.Worksheets(arr).PrintOut
End Sub
Private Sub UserForm_Initialize()
For Each ws In ActiveWorkbook.Sheets
If ws.Visible = True Then
Me.ListBox1.AddItem (ws.Name)
End If
Next
End Sub
Private Sub UserForm_QueryClose(Cancel As Integer, CloseMode As Integer)
Worksheets(1).Select
End Sub
--
Regards Ron de Bruin
(Win XP Pro SP-1 XL2002 SP-2)
www.rondebruin.nl
"John Shikella" <shik...@hotmail.com> wrote in message news:5927a6a.03051...@posting.google.com...
Sub Macro2()
'
' Macro2 Macro
' Macro recorded 15-05-2003 by kiat
'
'
Sheets(Array("Sheet1", "Sheet2", "Sheet3")).Select
Sheets("Sheet1").Activate
ActiveWindow.SelectedSheets.PrintPreview
End Sub
hint: If something Then Worksheets("Home Deleivery").Select False
"John Shikella" <shik...@hotmail.com> wrote in message
news:5927a6a.03051...@posting.google.com...