Hi All,
I am very new to VBA and I need your help on this code. My userform has a ListBox that gets populated with text. Each text string is a name of worksheet in the same workbook. The idea of this code is that when I highlight one or more of text string at the ListBox, a command button is supposed to look at the each of these worksheet name and read the data range from cell A1 to last string in column A and go to the next sheet and so on. Below is my code. I ran the code and I am getting an error at "Set ws.Name = ListBox1.Selected(i)". Can you look at the code and let me know what I am doing wrong.
Thanks
-----------------------------
Private Sub AvailableServices_Click()
Dim cell As Range
Dim rng As Range
Dim ws As Worksheet
For i = 0 To ListBox1.ListCount - 1
If ListBox1.Selected(i) = True Then
Set ws.Name = ListBox1.Selected(i)
Set rng = ws.Range("A1:")
For Each cell In rng.Cells
Me.ListBox2.AddItem cell.Value
Next cell
End If
Next i
End Sub
I am very new to VBA and I need your help on this code. My userform has a ListBox that gets populated with text. Each text string is a name of worksheet in the same workbook. The idea of this code is that when I highlight one or more of text string at the ListBox, a command button is supposed to look at the each of these worksheet name and read the data range from cell A1 to last string in column A and go to the next sheet and so on. Below is my code. I ran the code and I am getting an error at "Set ws.Name = ListBox1.Selected(i)". Can you look at the code and let me know what I am doing wrong.
Thanks
-----------------------------
Private Sub AvailableServices_Click()
Dim cell As Range
Dim rng As Range
Dim ws As Worksheet
For i = 0 To ListBox1.ListCount - 1
If ListBox1.Selected(i) = True Then
Set ws.Name = ListBox1.Selected(i)
Set rng = ws.Range("A1:")
For Each cell In rng.Cells
Me.ListBox2.AddItem cell.Value
Next cell
End If
Next i
End Sub