Hello,
Having the following problem.
I try opening a form with a simple listbox on it by a command button.
When opening from the sheet "data" with cmdbtn it works fine (Form on data )
When opening the same Form from the sheet "Start" also with a command button (Form on Start) the listbox won't work.
Where do i go wrong, by the way I've got so far by playing arround with vba found here or on the internet.
Using this code in the Form:
This is de code on both the command buttons:
Having the following problem.
I try opening a form with a simple listbox on it by a command button.
When opening from the sheet "data" with cmdbtn it works fine (Form on data )
When opening the same Form from the sheet "Start" also with a command button (Form on Start) the listbox won't work.
Where do i go wrong, by the way I've got so far by playing arround with vba found here or on the internet.
Using this code in the Form:
VBA Code:
Private Sub ListBox1_Click()
Dim ws As Worksheet
Set ws = Sheets("Data")
Dim sRow As Long
If Me.ListBox1.ListIndex > -1 Then
sRow = Me.ListBox1.ListIndex + 1
End If
Me.TextBox7.Text = Cells(sRow, 1) 'value from Column 5 (E)
Me.TextBox8.Text = Cells(sRow, 2)
Me.TextBox9.Text = Cells(sRow, 3)
Me.TextBox10.Text = Cells(sRow, 4)
End Sub
Private Sub UserForm_Activate()
Dim ws As Worksheet
Set ws = Sheets("Data")
Dim vCol As Variant
Dim Lrow As Long
Lrow = Sheets("Data").UsedRange.Rows(Sheets("Data").UsedRange.Rows.Count).Row
vCol = Sheets("Data").Range("A1:A" & Lrow).Value
Me.ListBox1.List = vCol
End Sub
Private Sub Userform_Initialize()
Dim ws As Worksheet
Set ws = Sheets("Data")
Dim vCol As Variant
Dim Lrow As Long
Lrow = Sheets("Data").UsedRange.Rows(Sheets("Data").UsedRange.Rows.Count).Row
vCol = Sheets("Data").Range("A1:A" & Lrow).Value
Me.ListBox1.List = vCol
End Sub
This is de code on both the command buttons:
Code:
Private Sub CommandButton1_Click()
UserForm1.Show
End Sub