Run a VBA after certain cell is typed in

jrisebo

Active Member
Joined
Mar 15, 2011
Messages
325
Office Version
  1. 365
Platform
  1. Windows
How do I get a SUB to run only after a certain cell is changed/typed in?
 

Excel Facts

Workdays for a market open Mon, Wed, Friday?
Yes! Use "0101011" for the weekend argument in NETWORKDAYS.INTL or WORKDAY.INTL. The 7 digits start on Monday. 1 means it is a weekend.
You would use a Worksheet_Change event procedure (see: Worksheet.Change event (Excel)).
If you provide us with more details, we can help you come up with the code.
Here is the code I have. I dont want it to run until C20 cell value is changed.

VBA Code:
Private Sub Worksheet_Change(ByVal Target As Range)
Static Counter As Long
If Counter = 0 Then
If Application.Min([C76:C80]) < 0 Then MsgBox "This causes a negative slope. Check your slope or enter it manually. See cells C76 to C80 for negative values, and then overide the slope at the anchor that is negative to the slope desired", vbExclamation
Counter = 1
End If
End Sub
 
Upvote 0
Try this:
VBA Code:
Private Sub Worksheet_Change(ByVal Target As Range)
    Static Counter As Long
    If Not Intersect(Target, Range("C20")) Is Nothing Then
        If Counter = 0 Then
            If Application.Min([C76:C80]) < 0 Then MsgBox "This causes a negative slope. Check your slope or enter it manually. See cells C76 to C80 for negative values, and then overide the slope at the anchor that is negative to the slope desired", vbExclamation
            Counter = 1
        End If
    End If
End Sub
 
Upvote 0
Solution
Private Sub Worksheet_Change(ByVal Target As Range) Static Counter As Long If Not Intersect(Target, Range("C20")) Is Nothing Then If Counter = 0 Then If Application.Min([C76:C80]) < 0 Then MsgBox "This causes a negative slope. Check your slope or enter it manually. See cells C76 to C80 for negative values, and then overide the slope at the anchor that is negative to the slope desired", vbExclamation Counter = 1 End If End If End Sub
Thanks,
That worked.
 
Upvote 0
You are welcome.
Glad I was able to help!

Let me know if you have any questions about the solution.
 
Upvote 0

Forum statistics

Threads
1,224,888
Messages
6,181,602
Members
453,055
Latest member
cope7895

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