We help IT Professionals succeed at work.

Auto run macro if user tried to type in cell

79 Views
Last Modified: 2016-01-24
Hi all,

Really at a loss on how to script this...

I need a macro to run if the user tries to type in any of the cells in the range (E7:E650). I know how to set it up if the user selects the cell it runs but this is not practical for this because I need the user to still be able to delete and copy the cell content ... To make matters a bit more complicated I need to make sure it doesn't cause conflicts with a user form which unloads data into those cells!

Any suggestions are greatly appreciated as I am well and truly stuck
Thanks in advance!
Comment
Watch Question

Commented:
Would using cell protection do the trick? You can disable it when your form is running and enable it when your form is not running. You should be able to set up specific protections when you protect your sheet (e.g., select cells).
Professor JMicrosoft Excel Expert
CERTIFIED EXPERT
Top Expert 2014

Commented:
you can put this code below in worksheet object
you macro to be called in would be in a standard module

replace YouMacro with your macro real name

Private Sub Worksheet_Change(ByVal Target As Range)
    Dim rng As Range
    Set rng = Range("E7:E650")
    If Intersect(Target, rng) Is Nothing Then Exit Sub
    For Each r In rng
        If r.Value = "" Then
            Exit Sub
        End If
    Next r
    Call YourMACRO
End Sub

Open in new window

Excel & VBA Expert
CERTIFIED EXPERT
Most Valuable Expert 2018
Awarded 2015
Commented:
This one is on us!
(Get your first solution completely free - no credit card required)
UNLOCK SOLUTION
Professor JMicrosoft Excel Expert
CERTIFIED EXPERT
Top Expert 2014

Commented:
@x5225642

Sktneer code works for you.

Author

Commented:
Hi ProfessorJimJam,
tried your code but it doesn't seem to do anything unfortunately.

Hi sktneer,
Tried your code too but again it does not appear to do anything and presents my other macro starting which is triggered from double clicking a cell in the same range

Sorry!
Subodh Tiwari (Neeraj)Excel & VBA Expert
CERTIFIED EXPERT
Most Valuable Expert 2018
Awarded 2015

Commented:
What macro you are calling within the code I proposed?
The code will work if user tries to change  the cell content by typing in it and once hits Enter then or deleting the cell content and as a result your desired macro should be called automatically in any case.

Author

Commented:
I don't know if this helps but is the code I have in worksheet object:

Private Sub Worksheet_Change(ByVal Target As Range)
    If Target.Count > 1 Then Exit Sub
    Application.EnableEvents = False
   
    If Not Intersect(Target, Range("E7:E650")) Is Nothing Then
    Call Ref
    Call PickFunctions
   
    End If
    Application.EnableEvents = True
End Sub
 
Private Sub Worksheet_BeforeDoubleClick(ByVal Target As Range, Cancel As Boolean)
 
If Intersect(Target, Range("E7:E650")) Is Nothing Then
    Exit Sub
Else
    Range("A1").Value = ActiveCell.Address
    Call PickFunctions
           
    End If
End Sub

Open in new window

Author

Commented:
Ok I restarted my spreadsheet and now the code above is working (not sure why that made any difference).
Thanks again for your help!
Subodh Tiwari (Neeraj)Excel & VBA Expert
CERTIFIED EXPERT
Most Valuable Expert 2018
Awarded 2015

Commented:
You're welcome. Glad it worked as per your requirement.
Unlock the solution to this question.
Join our community and discover your potential

Experts Exchange is the only place where you can interact directly with leading experts in the technology field. Become a member today and access the collective knowledge of thousands of technology experts.

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.