Specific row to write results

murty473

New Member
Joined
Aug 10, 2011
Messages
8
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

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
 

Excel Facts

Quick Sum
Select a range of cells. The total appears in bottom right of Excel screen. Right-click total to add Max, Min, Count, Average.
Raplace
Code:
lRow = ws.Cells(Rows.Count, 1) _
  .End(xlUp).Offset(1, 0).Row

with
Code:
lRow = 21
 
Upvote 0

Forum statistics

Threads
1,224,521
Messages
6,179,285
Members
452,902
Latest member
Knuddeluff

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