View Single Post
  #1   Report Post  
Posted to microsoft.public.excel.programming
Ron de Bruin Ron de Bruin is offline
external usenet poster
 
Posts: 11,123
Default copy sheets selected on user form

Try this Eileen

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).Copy
Unload Me
End Sub




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


"Eileen" wrote in message ...
I have a workbook with several sheets. A user form lists the sheet names in a
multi select list, lstWorksheets. When the user clicks OK, I want to copy all
selected sheets to one new workbook. Can someone please help me with the code
to accomplish this? Thanks.