ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   vba:Userform (https://www.excelbanter.com/excel-programming/316779-vba-userform.html)

ALEX

vba:Userform
 
I'd like to know how to make a userform that tells the

user to "Select Worksheets". Worksheet will be displayed

in the listbox as selected. Selected Worksheets will be

stored in an array for future processing, when command

button (Done) is click. Thanks in advance.


Bob Phillips[_6_]

vba:Userform
 
Alex,

Here is some code

Dim arysheets

Private Sub CommandButton1_Click()
Dim i As Long
Dim j As Long

With Me.ListBox1
For i = 0 To .ListCount - 1
If .Selected(i) Then
j = j + 1
If j = 1 Then
ReDim arysheets(1 To 1)
Else
ReDim Preserve arysheets(1 To j)
End If
arysheets(j) = .List(i)
End If
Next i
End With

End Sub

Private Sub UserForm_ACtivate()
Dim sh As Worksheet
For Each sh In ActiveWorkbook.Worksheets
Me.ListBox1.AddItem sh.Name
Next sh
End Sub


--

HTH

RP
(remove nothere from the email address if mailing direct)


"Alex" wrote in message
...
I'd like to know how to make a userform that tells the

user to "Select Worksheets". Worksheet will be displayed

in the listbox as selected. Selected Worksheets will be

stored in an array for future processing, when command

button (Done) is click. Thanks in advance.





All times are GMT +1. The time now is 11:30 AM.

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