How to automatically goto new line when click on add

Patriot2879

Well-known Member
Joined
Feb 1, 2018
Messages
1,259
Office Version
  1. 2010
Platform
  1. Windows
Hi all, i have te code below but it doesnt add the data onto a new line automatically can you help me please. For example i have a userform to fill out and in that i have a command button2 that when click will transfer the data added to sheet4, but it keeps overwriting on the same line and doesnt start a new line when userform is filled out again. hope you can help please.
Code:
Private Sub CommandButton2_Click()
Dim emptyRow As Long

With ThisWorkbook.Sheets("Sheet4")
   emptyRow = Cells(Rows.Count, "A").End(xlUp).Row + 1
 
   .Cells(emptyRow, 1).Value = TextBox1.Value
   .Cells(emptyRow, 2).Value = ComboBox1.Value

End With
Unload Me

End Sub
 
Last edited:

Excel Facts

Get help while writing formula
Click the italics "fx" icon to the left of the formula bar to open the Functions Arguments dialog. Help is displayed for each argument.
put a dot in front of Cells so it refers to the With instead of the active sheet.
 
Upvote 0
If you look at the code within your With statement you will see that for assigning emptyRow you have forgotten the dot before the Cells so you probably arent assignng the correct value to the variable.
 
Upvote 0
thank you :), as you can probaly tell i am quite new to this :)
 
Last edited:
Upvote 0

Forum statistics

Threads
1,223,905
Messages
6,175,297
Members
452,633
Latest member
DougMo

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