Hi.
I have the below code to add data from a userform to a worksheet. Within the userform i also have a listbox which displays the data.
Now what i am trying to do is for when a row of data is selected within the listbox, the text box input fields populate matching the data, so when i press add, the data overwrites.
I have been playing with the below, but dont think i am on the right path.. Any suggestions.
Thanks.
I have the below code to add data from a userform to a worksheet. Within the userform i also have a listbox which displays the data.
Now what i am trying to do is for when a row of data is selected within the listbox, the text box input fields populate matching the data, so when i press add, the data overwrites.
I have been playing with the below, but dont think i am on the right path.. Any suggestions.
Thanks.
Code:
Private Sub AddButton_Click()
Dim wks As Worksheet
Dim AddNew As Range
Set wks = Sheets("Samples")
Set AddNew = wks.Range("A65356").End(xlUp).Offset(1, 0)
AddNew.Offset(0, 0).Value = txt1.Text
AddNew.Offset(0, 1).Value = txt2.Text
AddNew.Offset(0, 2).Value = txt3.Text
AddNew.Offset(0, 3).Value = txt4.Text
AddNew.Offset(0, 4).Value = txt5.Text
AddNew.Offset(0, 9).Value = txt6.Text
AddNew.Offset(0, 10).Value = txt7.Text
lstDisplay.ColumnCount = 12
lstDisplay.RowSource = "'Samples'!A1:L65356"
End Sub
Private Sub ClearButton_Click()
Dim iControl As Control
For Each iControl In Me.Controls
If iControl.Name Like "txt*" Then iControl = VbNullStrong
Next
End Sub
Private Sub DeleteButton2_Click()
Dim ws As Worksheet
Dim I As Long
Set ws = Worksheets("Samples")
With ws
For I = 1 To .Range("A65356").End(xlUp).Row - 1
If lstDisplay2.Selected(I) Then
.Rows(I + 1).Delete
End If
Next I
End With
End Sub
Code:
Private Sub lstDisplay_Click()
txt1.Value = lstDisplay.Value
End Sub
Private Sub txt1_Change()
Dim rCell As Range
With lstDisplay
Set rCell = Range(.RowSource).Offset(.ListIndex).Resize(1)
rCell.Value = txt1.Value
End With
End Sub