Run Macro from Cell Value

eggtimer

Board Regular
Joined
Apr 16, 2003
Messages
125
Hi

I've searched the site and found some cool code, below, which based on a value entered into a cell will run a macro

Well I haven't got that far yet, I thought I would makes sure I could get it to work with the message box first. I pasted the code in entered a value in the cell and the message box appeared, great.

But the cell I want to link it to is not manually updated it is updated via a "spinner" on the forms toolbar and when the spinner updates the value, the message box does not appear.

Which I also find a bit odd as i have to make sure the cell is unlocked on a protected sheet for it to update, which made me think it was bound to work for this.

Does anyone know how to overcome this?

Private Sub Worksheet_Change(ByVal Target As Excel.Range)
If Not Application.Intersect(Target, Range("M1")) Is Nothing Then
If Target.Value < 5 Then
MsgBox "replace this line with your macro"
End If
End If
End Sub


Thanks

Wayne
 

Excel Facts

Waterfall charts in Excel?
Office 365 customers have access to Waterfall charts since late 2016. They were added to Excel 2019.
Hi Andy

Thanks for the reply

But I'm afraid it has just confused me. I've searched all over for the Change Event Procedure, but couldn't find it.

So i have tried to paste the code into every available place I could find and nothing I have done has made it work.

Where am I going wrong

Cheers

Wayne
 
Upvote 0
Use a Spinner from the Control Toolbox instead of from the Forms Toolbar. Its Change event procedure will be in the module for the sheet.
 
Upvote 0
Hi Andy

Sorry Bud, but, I'm misssing something

I've changed my spinner to activex and thats cool, but i don't know where to past the code

I've tried pasting it below and that changes it from spinbutton1 to worksheet, so i tried pasting it in the middle and i got a compile error

is this the two bits of code i am trying to put together?

Private Sub SpinButton1_Change()

End Sub

Private Sub Worksheet_Change(ByVal Target As Excel.Range)
If Not Application.Intersect(Target, Range("M1")) Is Nothing Then
If Target.Value < 5 Then
Rows("8:145").Select
Selection.EntireRow.Hidden = True
End If
End If
End Sub
 
Upvote 0
Scrap the Worksheet_Change code and try:

Code:
Private Sub SpinButton1_Change() 
   If Spinner1.Value < 5 Then 
      Rows("8:145").EntireRow.Hidden = True 
   Else
      Rows("8:145").EntireRow.Hidden = False
   End If
End Sub
 
Upvote 0

Forum statistics

Threads
1,203,397
Messages
6,055,165
Members
444,767
Latest member
bryandaniel5

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