ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   copy sheets selected on user form (https://www.excelbanter.com/excel-programming/307488-re-copy-sheets-selected-user-form.html)

Ron de Bruin

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.





All times are GMT +1. The time now is 06:22 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
ExcelBanter.com