Press Enter to run a Command Button - Driving me CRAZY

Jimmy110

Board Regular
Joined
Feb 28, 2022
Messages
63
Office Version
  1. 365
Platform
  1. Windows
Hi All,

Really need your help as I just cant get this to work.... Wanting to type a weight into cell C6, then I have a command button that copies the cell, transfers it to the bottom of a table in a different sheet and then deletes the value from the original cell....

Id love it if after typing the value in C6, all I had to do was press Enter and it would be like pressing the command button.

My code currently looks like this:



VBA Code:
Private Sub CommandButton1_Click()
Dim Customername As String, Customerphone As String
Worksheets("sheet1").Select
Customername = Range("C6")
Worksheets("sheet2").Select
Worksheets("sheet2").Range("A1").Select
If Worksheets("sheet2").Range("A1").Offset(1, 0) <> "" Then
Worksheets("sheet2").Range("A1").End(xlDown).Select
End If
ActiveCell.Offset(1, 0).Select
ActiveCell.Value = Customername

Worksheets("sheet1").Select
Worksheets("Sheet1").Range("C6").ClearContents
Worksheets("sheet1").Range("C6").Select



End Sub


Any ideas?
 
Last edited by a moderator:
You have the code in the wrong place, it needs to go in the sheet module (where your command button code is), not a standard module.
 
Upvote 0

Excel Facts

How to change case of text in Excel?
Use =UPPER() for upper case, =LOWER() for lower case, and =PROPER() for proper case. PROPER won't capitalize second c in Mccartney
You have the code in the wrong place, it needs to go in the sheet module (where your command button code is), not a standard module.
Getting somewhere now! Thanks for that.... so its transferring the data...but a dialogue box is coming up with "1" in it...I press enter and then it changes to "2" and so on and so on...takes about 6 presses of enter to clear it...then it updates??? Whats your thoughts?
 
Upvote 0
Use the code I originally provided, which doesn't have the messages boxes.
 
Upvote 0
You're welcome & thanks for the feedback.
 
Upvote 0
You're welcome & thanks for the feedback.
Could I be cheeky and ask how I add a button on Sheet1 to delete the last row of the Table in "A"?

Logic being if someone makes a mistake entering a number, its easy to remove?
 
Upvote 0
As that's a completely different question, it needs a new thread. Thanks
 
Upvote 0

Forum statistics

Threads
1,216,049
Messages
6,128,496
Members
449,455
Latest member
jesski

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