Triggering a worksheet_change with a command button?

Beware Wet Paint

New Member
Joined
Jul 9, 2013
Messages
34
Can worksheet_change macros only be set up to automatically run in response to data changes? If there anyway to set it to respond to a command button?
 

Excel Facts

Can Excel fill bagel flavors?
You can teach Excel a new custom list. Type the list in cells, File, Options, Advanced, Edit Custom Lists, Import, OK
If you want your script to only run when you click a button. You do not need a Worksheet change script.

Tell us exactly what your wanting to do.
Provide specific details
 
Upvote 0
I would like to be able to click a command button and have specific cells in a worksheet checked to see if their value is greater than 5, if any are greater than 5 I'd like to have a message box pop up saying the limit has been succeeded. The problem I seem to have is that the value of the cells being checked is calculated by formula. E.g I'd want A1 checked but A1=B1+C1, it isn't a direct value input.

I hope that's clear enough, I'm not sure how else to word it :/
 
Upvote 0
So why would this not work.
Now this one only checks one cell.
If you want it to check more then one give me a more detailed example.
This example checks Range("A1") for being greater then 5

Code:
Sub Check_Cell_Value()
'Modified 11/4/2018 3:27:43 PM  EST
If Range("A1").Value > 5 Then MsgBox "the limit has been succeeded"
End Sub
 
Upvote 0
Ok so for example I'd want to check A1, A3, A5 (all of which are B+C) and if any of them were greater than 5 I'd want the message box and if possible for that to only pop up once as opposed to three times is A1,A3,A5 were all greater than 5
 
Upvote 0
Try this:
Now this is for checking three ranges.
If you wanted to check 12 different ranges we would need to do this some other way.

Code:
Sub Check_Cell_Value()
'Modified  11/4/2018  4:27:30 PM  EST
If Range("A1") > 5 Or Range("A3") > 5 Or Range("A5") > 5 Then MsgBox "the limit has been succeeded"
End Sub
 
Upvote 0
Here is another way to do it:
Code:
Sub New_Check()
'Modified  11/4/2018  4:48:04 PM  EST
Dim r As Range
Dim x As Long
x = 0
For Each r In Range("A1,A3,A5")
    With r.Value
        Select Case r.Value
            Case Is > 5
                x = x + 1
        End Select
    End With
Next
If x > 0 Then MsgBox "the limit has been succeeded"
End Sub
 
Upvote 0
Here is another way to do it:
Code:
Sub New_Check()
'Modified  11/4/2018  4:48:04 PM  EST
Dim r As Range
Dim x As Long
x = 0
For Each r In Range("A1,A3,A5")
    With r.Value
        Select Case r.Value
            Case Is > 5
                x = x + 1
        End Select
    End With
Next
If x > 0 Then MsgBox "the limit has been succeeded"
End Sub

You're a genius!
 
Upvote 0

Forum statistics

Threads
1,224,820
Messages
6,181,161
Members
453,021
Latest member
Justyna P

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