VBA code run when I presse Enter

KlausW

Active Member
Joined
Sep 9, 2020
Messages
385
Office Version
  1. 2016
Platform
  1. Windows
Hi, I found this VBA code here on MrExcel and it works really well. The only thing I could think of was that I should not enter any text in column D and press ENTER. If I stand in column D and do not type anything, the VBA code does not run. But if I write something in column D run the VBA code. Anyone who can help? Any help will be appreciated. Best Regards Klaus W

VBA Code:
Private Sub worksheet_change(ByVal target As Range)

If Not Intersect(target, Sheets("Prisliste").Range("d9:d4000")) Is Nothing Then

 Call Prisliste_Overfør_Varer_Klik
 
End If

End Sub
 
If you want to run code when a cell is edited but only if the editing is followed by pressing the ENTER key, you can use try something like this:

In the worksheet module:
VBA Code:
Option Explicit

#If VBA7 Then
    Private Declare PtrSafe Function GetAsyncKeyState Lib "user32" (ByVal vKey As Long) As Integer
#Else
    Private Declare Function GetAsyncKeyState Lib "user32" (ByVal vKey As Long) As Integer
#End If

Private Sub Worksheet_Change(ByVal Target As Range)
    If GetAsyncKeyState(VBA.vbKeyReturn) Then
        MsgBox Target.Address & " was edited and followed by pressing the ENTER key"
    End If
End Sub

Other navigation keys such as TAB, Arrow keys etc as well as the mouse won't run the code
Hi I can't get it to work but I have tried this. Can it work? KW
 
Upvote 0

Excel Facts

Back into an answer in Excel
Use Data, What-If Analysis, Goal Seek to find the correct input cell value to reach a desired result

Forum statistics

Threads
1,215,214
Messages
6,123,665
Members
449,114
Latest member
aides

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