Melani_6696
New Member
- Joined
- Jul 14, 2021
- Messages
- 2
- Office Version
- 365
- Platform
- Windows
Hello,
First time posting and a beginner on VBA but here it goes. I have created a list box based on the names of the tabs I have on an excel file but now I want to be able to add text to a tab if selected on the listbox, I havnt been able to make it work :/. Below what i tried... but i dont think is right? anybody can help out?
Private Sub CommandButton1_Click()
Dim i As Long, c As Long
Dim SheetArray() As String
With ActiveSheet.ListBoxSh
For i = 0 To .ListCount - 1
If .Selected(i) Then
ReDim Preserve SheetArray(c)
texbox2.Value = SheetArray(c).Range("B16").Value
SheetArray(c) = .List(i)
c = c + 1
End If
First time posting and a beginner on VBA but here it goes. I have created a list box based on the names of the tabs I have on an excel file but now I want to be able to add text to a tab if selected on the listbox, I havnt been able to make it work :/. Below what i tried... but i dont think is right? anybody can help out?
Private Sub CommandButton1_Click()
Dim i As Long, c As Long
Dim SheetArray() As String
With ActiveSheet.ListBoxSh
For i = 0 To .ListCount - 1
If .Selected(i) Then
ReDim Preserve SheetArray(c)
texbox2.Value = SheetArray(c).Range("B16").Value
SheetArray(c) = .List(i)
c = c + 1
End If