hi
I have this code doesn't work in initialize user form . it just work in commandbutton when I put this
but when I put into initialize user form
it doesn't work at all
my request when I select item from listbox automatically show the number of row in textbox1
any suggestion to fix it ,please ?
I have this code doesn't work in initialize user form . it just work in commandbutton when I put this
VBA Code:
Private Sub CommandButton1_Click()
Dim n As Long, Rws As String
With ListBox1
For n = 0 To .ListCount - 1
If .Selected(n) Then
Rws = Rws & IIf(Rws = "", n + 1, ", " & n + 1)
End If
Next n
If Rws <> "" Then
TextBox1.Value = Rws
MsgBox "Selected Rows :- " & Rws
End If
End With
End Sub
but when I put into initialize user form
Code:
Private Sub UserForm_Initialize()
Dim n As Long, Rws As String
With ListBox1
.ListBox1.List = Sheets("Sheet1").ListObjects("Table1").DataBodyRange.Value
For n = 0 To .ListCount - 1
If .Selected(n) Then
Rws = Rws & IIf(Rws = "", n + 1, ", " & n + 1)
End If
Next n
If Rws <> "" Then
TextBox1.Value = Rws
MsgBox "Selected Rows :- " & Rws
End If
End With
End Sub
my request when I select item from listbox automatically show the number of row in textbox1
any suggestion to fix it ,please ?