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:

Excel Facts

Show numbers in thousands?
Use a custom number format of #,##0,K. Each comma after the final 0 will divide the displayed number by another thousand
Hi & welcome to MrExcel.
How about
VBA Code:
Private Sub Worksheet_Change(ByVal Target As Range)
   If Target.CountLarge > 1 Then Exit Sub
   If Target.Address(0, 0) = "C6" And Target.Value <> "" Then
      Sheets("Sheet2").Range("A" & Rows.count).End(xlUp).Offset(1).Value = Target.Value
      Target.ClearContents
   End If
End Sub
This needs to go in the Sheet1 code module
 
Upvote 0
Hi & welcome to MrExcel.
How about
VBA Code:
Private Sub Worksheet_Change(ByVal Target As Range)
   If Target.CountLarge > 1 Then Exit Sub
   If Target.Address(0, 0) = "C6" And Target.Value <> "" Then
      Sheets("Sheet2").Range("A" & Rows.count).End(xlUp).Offset(1).Value = Target.Value
      Target.ClearContents
   End If
End Sub
This needs to go in the Sheet1 code module
Thanks Fluff....

Doesnt seem to do anything that? Copied it into the blank sheet1 module?

any other ideas?
 
Upvote 0
Is C6 being changed manually & is it on Sheet1?
 
Upvote 0
Is C6 being changed manually & is it on Sheet1?
Yeah, C6 is a manual entry at the moment....so for example, someone types in 15.1 and then next to the cell is a command button that does the rest....it would be great if they didn't have to press the command button. Doesn't sound a lot, but slows them down massively

Thanks again
 
Upvote 0
In that case it should automatically copy across when you change the value of C6.
If you try this, do you get any message boxes
VBA Code:
Private Sub Worksheet_Change(ByVal Target As Range)
   MsgBox 1
   If Target.CountLarge > 1 Then Exit Sub
   MsgBox 2
   If Target.Address(0, 0) = "C6" And Target.Value <> "" Then
      MsgBox 3
      Sheets("Sheet2").Range("A" & Rows.count).End(xlUp).Offset(1).Value = Target.Value
      Target.ClearContents
   End If
End Sub
 
Upvote 0
In that case it should automatically copy across when you change the value of C6.
If you try this, do you get any message boxes
VBA Code:
Private Sub Worksheet_Change(ByVal Target As Range)
   MsgBox 1
   If Target.CountLarge > 1 Then Exit Sub
   MsgBox 2
   If Target.Address(0, 0) = "C6" And Target.Value <> "" Then
      MsgBox 3
      Sheets("Sheet2").Range("A" & Rows.count).End(xlUp).Offset(1).Value = Target.Value
      Target.ClearContents
   End If
End Sub
no, no messages or warnings...just nothing happening.

here's a link to a copy of the sheet Giveaway Calc Copy.xlsm maybe you can make more sense of it?
 
Upvote 0

Forum statistics

Threads
1,214,646
Messages
6,120,716
Members
448,985
Latest member
chocbudda

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