Get fields in worksheet

  • Thread starter Thread starter Sahak
  • Start date Start date
S

Sahak

I have records which have four columns. I have a listBox
in User Form which shows all records. I would like to get
all four fields of the record in worksheet cells when I
will select a record from the ListBox. Is it possible?
Thanks,
Sahak
 
How about this:

Option Explicit
Private Sub ListBox1_Click()

Dim iCtr As Long
Dim DestCell As Range

With ActiveSheet
Set DestCell = .Cells(.Rows.Count, "A").End(xlUp).Offset(1, 0)
End With

With Me.ListBox1
If .ListIndex > -1 Then
For iCtr = 0 To 3
DestCell.Offset(0, iCtr).Value = .List(.ListIndex, iCtr)
Next iCtr
End If
End With

End Sub
Private Sub UserForm_Initialize()
With Me.ListBox1
.ColumnCount = 4
.RowSource _
= Worksheets("sheet1").Range("A1:d10").Address(external:=True)
End With
End Sub
 
Back
Top