Hi all,
I have a userform with textboxes populated by a list box,
What I am hoping to achieve is to be able to edit any textbox and update the change to the data sheet "People" using a button,
Secondly I would like to populate the text boxes with new data and add to the same sheet the next available column,
If anyone can help it would be greatly appreciated here is all the code a currently have in use,
Many Thanks,
I have a userform with textboxes populated by a list box,
What I am hoping to achieve is to be able to edit any textbox and update the change to the data sheet "People" using a button,
Secondly I would like to populate the text boxes with new data and add to the same sheet the next available column,
If anyone can help it would be greatly appreciated here is all the code a currently have in use,
Many Thanks,
VBA Code:
Private Sub UserForm_Activate()
Set sh = ThisWorkbook.Worksheets("People")
Dim iRow As Long
iRow = sh.Range("A" & Rows.Count).End(xlUp).Row
'to populate listbox from Database sheet
With Me.ListBox1
.ColumnCount = 32
.ColumnHeads = True
.ColumnWidths = "120,100,60,80,100,60,100,120,50,80,80,80,80,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50"
.RowSource = "People!A2:AF" & iRow
End With
End Sub
Private Sub ListBox1_Click()
Dim Col As Long, SelectedRow As Long
SelectedRow = Me.ListBox1.ListIndex + 2
'Loads textboxes with selected range values
For Col = 1 To 32
Me.Controls("TextBox" & Col).Value = sh.Cells(SelectedRow, Col).Text
Next Col
End Sub
Private Sub Clear_Click()
Dim ctrl As Control ' CREATE A CONTROL OBJECT.
' LOOP THROUGH EACH CONTROL, CHECK IF THE CONTROL IS A TEXTBOX.
For Each ctrl In Me.Controls
If TypeName(ctrl) = "TextBox" Then
ctrl.Value = "" 'CLEAR THE VALUE.
End If
Next ctrl
Dim X As Control
For Each X In Me.Controls
If TypeOf X Is MSForms.CheckBox Then X.Value = False
Next
End Sub