• Hi All

    Please note that at the Chandoo.org Forums there is Zero Tolerance to Spam

    Post Spam and you Will Be Deleted as a User

    Hui...

  • When starting a new post, to receive a quicker and more targeted answer, Please include a sample file in the initial post.

To capture ListBox value for array: Sheets(Array("Sheet1", "Sheet3")).Copy

Experts,

A quick question;
If we can get listbox1 value to select a sheet the below way;
Sheets(ListBox1.Value).Copy

How to get listbox1 value to select multiple sheet where I have array
.Sheets(Array("Sheet1", "Sheet3")).Copy

Please help.
 
@NARAYANK991 ; it didn't help. That was actually about multi-select listbox which was done already from my side.
The present requirement is to capture the selected value say sheet name into the VBA code;
.Sheets(Array("Sheet1", "Sheet3")).Copy

If I select sheet1 and sheet3 from the listbox, that should capture like the above shown method. Any help?
 
Hi Karthik ,

The most disappointing words a member wants to hear are :
it didn't help.
Try this :
Code:
Private Sub ListBox1_LostFocus()
            Dim Selected_Sheets As String
            Dim Sheets_Array As Variant
            Dim i As Integer
         
            With Me
                For i = 1 To .ListBox1.ListCount
                    If .ListBox1.Selected(i - 1) Then
                        Selected_Sheets = Selected_Sheets & "," & .ListBox1.List(i - 1)
                    End If
                Next
                Selected_Sheets = Mid(Selected_Sheets, 2)
                Sheets_Array = Split(Selected_Sheets, ",")
               
                Application.DisplayAlerts = False
                ThisWorkbook.Worksheets(Sheets_Array).Copy
                Application.DisplayAlerts = True
            End With
End Sub
Narayan
 
Back
Top