Hello,
I use an userform to populate a sheet, and this works fine.
I have added the option to edit / delete data from the data-sheet, and that works, however it updates the wrong rows when there are empty rows in the data-sheet.
Every row of data has an serial number, their are no doubles.
The code that I am using, just for updating (found on a forum and adapted to my needs)
Code
Private Sub CommandButton6_Click() ' Update button
Dim SLNO As Integer
Sheets("Reports").Select
If Me.TextBox27.Value = "" Then
MsgBox "Shift Can Not be Blank!!!", vbExclamation, "SL No"
Exit Sub
End If
SLNO = Me.TextBox27.Value
'Sheets("Reports").Select
Dim rowselect As Double
Dim msg As String
Dim ans As String
rowselect = Me.TextBox27.Value
rowselect = rowselect + 1
Rows(rowselect).Select
Cells(rowselect, 3) = Me.TextBox1.Value
Cells(rowselect, 6) = Me.ComboBox7.Value
Cells(rowselect, 2) = Me.ComboBox3.Value
Cells(rowselect, 4) = Me.ComboBox4.Value
Cells(rowselect, 7) = Me.TextBox4.Value
Cells(rowselect, 8) = Me.TextBox5.Value
Cells(rowselect, 9) = Me.Label76.Caption
Cells(rowselect, 34) = Me.TextBox6.Value
Cells(rowselect, 35) = Me.TextBox22.Value
Cells(rowselect, 14) = Me.TextBox9.Value
Cells(rowselect, 15) = Me.TextBox10.Value
Cells(rowselect, 16) = Me.TextBox11.Value
Cells(rowselect, 17) = Me.TextBox12.Value
Cells(rowselect, 18) = Me.TextBox13.Value
Cells(rowselect, 19) = Me.TextBox14.Value
Cells(rowselect, 24) = Me.TextBox15.Value
Cells(rowselect, 29) = Me.TextBox16.Value
Cells(rowselect, 36) = Me.TextBox17.Value
Cells(rowselect, 20) = Me.TextBox18.Value
Cells(rowselect, 25) = Me.TextBox19.Value
Cells(rowselect, 30) = Me.TextBox20.Value
Cells(rowselect, 37) = Me.TextBox21.Value
Cells(rowselect, 21) = Me.ComboBox6.Value
Cells(rowselect, 26) = Me.ComboBox5.Value
Cells(rowselect, 31) = Me.ComboBox8.Value
Cells(rowselect, 38) = Me.ComboBox9.Value
Cells(rowselect, 22) = Me.ComboBox12.Value
Cells(rowselect, 27) = Me.ComboBox11.Value
Cells(rowselect, 32) = Me.ComboBox13.Value
Cells(rowselect, 39) = Me.ComboBox10.Value
Cells(rowselect, 23) = Me.ComboBox16.Value
Cells(rowselect, 28) = Me.ComboBox15.Value
Cells(rowselect, 33) = Me.ComboBox17.Value
Cells(rowselect, 40) = Me.TextBox26.Value
rowselect = rowselect - 1
msg = "Shift Info " & rowselect & " Successfully Updated...Continue?"
Unload Me
ans = MsgBox(msg, vbYesNo, "Update")
If ans = vbYes Then
Shift.Show
Else
Sheets("Reports").Select
End If
End Sub
Display More
How can I change the code so it will ignore the empty rows (if there are any).
Overwriting the wrong rows is not an option.
Hope someone can help me, really appreciate all the help.