Run Macro if Enter is Pressed & in a certain row

johneh

New Member
Joined
May 10, 2004
Messages
25
We use hand scanners while doing phyiscal inventory and if scans into a Excel workbook.

I am try to figure out how to create a macro that will run only...
If in Column C and enter is pressed

Any ideas?
Thanks
 

Excel Facts

Copy a format multiple times
Select a formatted range. Double-click the Format Painter (left side of Home tab). You can paste formatting multiple times. Esc to stop
Is the scanner entering data into column C and you are pressing Enter to confirm this or are you pressing enter to move down a cell? On ask as I've never used one myself so not sure exactly how they work entering data into a worksheet.

Dom
 
Upvote 0
This seemed to work for me...
In your Sheet Code Module paste in

Code:
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
If Intersect(Target, Range("C:C")) Is Nothing Then Exit Sub
MsgBox "you are in Column C"  'REPLACE THIS WITH DESIRED CODE
End Sub
 
Upvote 0
You could also use onkey

Code:
Sub StartOnKey()
'Run this sub to make the ENTER-key run "SubMyCode"
Application.OnKey "{ENTER}", "SubMyCode"
End Sub

Sub SubMyCode()
If ActiveCell.Column = 3 Then
'your code here
End If
End Sub


Sub StopOnKey()
'Run this sub to release the onkey event
Application.OnKey "{ENTER}"
End Sub


If you mean to use the CR key, replace {ENTER} with ~
 
Last edited:
Upvote 0

Forum statistics

Threads
1,215,326
Messages
6,124,256
Members
449,149
Latest member
mwdbActuary

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