Hi,
I'm using the below macros in order to enter data to the sheet from my userform when the button is selected.
My problem is, it's always writing to the first empty row. If I don't delete the data in raw, data goes to below row which is empty.
I would like the data always to be written to the specific row. I have 4 comboboxes and let's say to A21,B21,C21,D21...
I appreciate for your help.
Kind Regards
I'm using the below macros in order to enter data to the sheet from my userform when the button is selected.
My problem is, it's always writing to the first empty row. If I don't delete the data in raw, data goes to below row which is empty.
I would like the data always to be written to the specific row. I have 4 comboboxes and let's say to A21,B21,C21,D21...
I appreciate for your help.
Kind Regards
Code:
Private Sub cmdAdd_Click()
'Your existing code for the button
Me.Hide
Dim lRow As Long
Dim lPart As Long
Dim ws As Worksheet
Set ws = Worksheets("KPIResult")
'find first empty row in database
lRow = ws.Cells(Rows.Count, 1) _
.End(xlUp).Offset(1, 0).Row
lPart = Me.Turkcell1.ListIndex
'find first empty row in database
If Trim(Me.Turkcell4.Value) = "" Then
Me.Turkcell4.SetFocus
MsgBox "You have to fill KPI Name"
Exit Sub
End If
'copy the data to the database
With ws
.Cells(lRow, 1).Value = Me.Turkcell1.Value
.Cells(lRow, 2).Value = Me.Turkcell2.Value
.Cells(lRow, 3).Value = Me.Turkcell3.Value
.Cells(lRow, 4).Value = Me.Turkcell4.Value
End With
'clear the data
Me.Turkcell1.Value = ""
Me.Turkcell2.Value = ""
Me.Turkcell3.Value = ""
Me.Turkcell4.Value = ""
Me.Turkcell4.SetFocus