VBA - on Enter run macro?

EssKayKay

Active Member
Joined
Jan 5, 2003
Messages
417
Office Version
  1. 2007
Platform
  1. Windows
I’m back,

I’m not sure this is exactly what I want but I’d like to start here. What I want is a VBA routine to run a macro when an entry (or more particularly and edit) is made to a cell in range M33:M400 where an entry has already been made. That is, something like if the existing cell is >0 then OnEnter do this.

Like I said, I’m not positive this will do what I want but I’d like try this.

Thanks,
Steve K.
 

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
See if this gives you what you want (worksheet change event to be put in the sheet module of the sheet in question)

Rich (BB code):
Private Sub Worksheet_Change(ByVal Target As Range)
    If Target.Cells.CountLarge = 1 And Not Intersect(Range("M33:M400"), Target) Is Nothing Then
        Application.EnableEvents = False
        Dim NewVal As String, OldVal As String
        NewVal = Target.Value
        Application.Undo
        OldVal = Target.Value
        
            If Len(OldVal) > 0 And OldVal <> NewVal Then
                Target = NewVal
                Target.Offset(1).Select
                
                'Call Your Macro Here '<-- *** NOTE ***
                MsgBox "This is a demo" '<-- *** Delete after demo ***
            Else
                Target = NewVal
                Target.Offset(1).Select
            End If
            
        Application.EnableEvents = True
    End If
End Sub
 
Upvote 0
Solution
Thank you very much Kevin. This is doing what I wanted. However, as expected, I ran into some other issues. I really don’t want to say this but I think I’m going to go back to the drawing board on this project – just too many little annoyances if not actual problems. I will use your code in the redesign. I’ve been working on this project for many months. Oh well. . .

Again, much appreciated,
Steve
 
Upvote 0
Thanks for the feedback Steve, and if you wanted to share the other issues you've encountered, I'm sure you'll find help here, 😉
 
Upvote 0

Forum statistics

Threads
1,224,833
Messages
6,181,240
Members
453,026
Latest member
cknader

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