Help with userform to edit existing rows.

Seacowdaz

New Member
Joined
Mar 20, 2018
Messages
11
Hello. i hope somebody is able to help me, my knowledge of VBA isn't great to begin with and i havnt been able to find the answer online (pr at least one that i can follow) .

i have a spreadsheet with several userforms. one to add, remove and edit existing users on a sheet. the add and delete ones i have been able to do but i need some help with the VBA for the form to edit. so far i have the below which populates a combo box which you can then use to select which person to edit. The code i have pulls throw the data from the relevant columnsinto the userform, but it won't allow me to edit the data on the form and have that written back to the sheet.

VBA Code:
Private Sub ComboBox2_Change()
Dim i As Long, LastRow As Long
LastRow = Sheets("Daily Report").Range("AL" & Rows.Count).End(xlUp).Row
For i = 1 To LastRow
If Sheets("Daily Report").Cells(i, "D").Value = (Me.ComboBox2) Or _
Sheets("Daily Report").Cells(i, "D").Value = Val(Me.ComboBox2) Then
Me.TextBox1 = Sheets("Daily Report").Cells(i, "D").Value
Me.TextBox2 = Sheets("Daily Report").Cells(i, "AK").Value
Me.TextBox3 = Sheets("Daily Report").Cells(i, "B").Value
Me.TextBox4 = Sheets("Daily Report").Cells(i, "A").Value
Me.TextBox5 = Sheets("Daily Report").Cells(i, "C").Value
Me.ComboBox1 = Sheets("Daily Report").Cells(i, "AM").Value
Me.TextBox6 = Sheets("Daily Report").Cells(i, "AE").Value
Me.TextBox7 = Sheets("Daily Report").Cells(i, "AF").Value
End If
Next

End Sub

Would someone be able to help me with what i need to add / change to write it back to the sheet?, and if possible help me format so that TextBox 6 and 7 show the time in the right format rather than convert it to text please? Or have it so that if a textbox is blank it doesnt overwrite the existing value on the row i have linked a sample sheet with some dummy data

Thank you in advance for any help

Sample Sheet
 
VBA Code:
Private Sub ComboBox2_Change()
Dim i As Long, LastRow As Long
LastRow = Sheets("Daily Report").Range("AL" & Rows.Count).End(xlUp).Row
For i = 1 To LastRow
If Sheets("Daily Report").Cells(i, "D").Value = (Me.ComboBox2) Or _
Sheets("Daily Report").Cells(i, "D").Value = Val(Me.ComboBox2) Then
Me.TextBox1 = Sheets("Daily Report").Cells(i, "D").Value
Me.TextBox2 = Sheets("Daily Report").Cells(i, "AK").Value
Me.TextBox3 = Sheets("Daily Report").Cells(i, "B").Value
Me.TextBox4 = Sheets("Daily Report").Cells(i, "A").Value
Me.TextBox5 = Sheets("Daily Report").Cells(i, "C").Value
Me.ComboBox1 = Sheets("Daily Report").Cells(i, "AM").Value
Me.TextBox6 = Sheets("Daily Report").Cells(i, "AE").Value
Me.TextBox7 = Sheets("Daily Report").Cells(i, "AF").Value
End If
Next

Me.TextBox6 = Format(Now, "HH:MM Am/Pm")
Me.TextBox7 = Format(Now, "HH:MM Am/Pm")


End Sub
 
Upvote 0

Excel Facts

Move date out one month or year
Use =EDATE(A2,1) for one month later. Use EDATE(A2,12) for one year later.

Forum statistics

Threads
1,214,951
Messages
6,122,446
Members
449,083
Latest member
Ava19

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top