Cell reference trigger macro

Abvlecxe

Board Regular
Joined
Sep 10, 2015
Messages
53
Hello, I am trying to call macros based on the number in one cell but only the change for numbers 1 & 2 seem to work:

Private Sub Worksheet_Change(ByVal Target As Excel.Range)
If Target.Cells.Count > 1 Then Exit Sub
If IsNumeric(Target) And Target.Address = "$D$27" Then
Select Case Target.Value
Case 1: Call Macro1
Case 2: Call Maco2
Case 3: Call Macro3
Case 4: Call Macro4
Case 5: Call Macro5
End Select
End If
End Sub

Any help would be apreciated, thanks
 

Excel Facts

What is the last column in Excel?
Excel columns run from A to Z, AA to AZ, AAA to XFD. The last column is XFD.
Try:
Code:
Private Sub Worksheet_Change(ByVal Target As Excel.Range)
    If Intersect(Target, Range("D27")) Is Nothing Then Exit Sub
    If Target.Cells.Count > 1 Then Exit Sub
    If IsNumeric(Target) Then
        Select Case Target.Value
            Case Is = 1: Call macro1
            Case Is = 2: Call macro2
            Case Is = 3: Call macro3
            Case Is = 4: Call macro4
            Case Is = 5: Call macro5
        End Select
    End If
End Sub
If the target is a number, you have to use "Case Is ="
 
Last edited:
Upvote 0
Hi, thanks for the reply unfortunately the same issue, if i change to anything but 1 or 2 nothing happens!

Try:
Code:
Private Sub Worksheet_Change(ByVal Target As Excel.Range)
    If Intersect(Target, Range("D27")) Is Nothing Then Exit Sub
    If Target.Cells.Count > 1 Then Exit Sub
    If IsNumeric(Target) Then
        Select Case Target.Value
            Case Is = 1: Call macro1
            Case Is = 2: Call macro2
            Case Is = 3: Call macro3
            Case Is = 4: Call macro4
            Case Is = 5: Call macro5
        End Select
    End If
End Sub
If the target is a number, you have to use "Case Is ="
 
Upvote 0
I tried the macro with some dummy data and it worked properly. Is the value in D27 inserted manually or is it the result of a formula? This is probably a stupid question but do macros 3 to 5 exist?
 
Upvote 0
The cell is from a data validation list numbers 1 to 5, i even tried just typing in the number but still nothing, will try removing validation and try on another worksheet to check.

Yea i need 5 as depending on what number is picked will then trigger the appropriate macro to then organise the worksheet.

Thanks

I tried the macro with some dummy data and it worked properly. Is the value in D27 inserted manually or is it the result of a formula? This is probably a stupid question but do macros 3 to 5 exist?
 
Upvote 0
Check the values in your data validation list for beginning or trailing spaces for numbers 3, 4 and 5. If there are extra spaces they won't be visible but they will affect the macro.
 
Upvote 0
Try this, just to make sure that everyone (including VBA) is working with numbers.
Code:
Select Case Val(Target.Value)
 
Upvote 0
The code mumps posted works for me as well. By any chance are you using code that turns off events? i.e.

Code:
Application.EnableEvents = False
 
Last edited:
Upvote 0
Code:
Private Sub Worksheet_Change(ByVal Target As Range)
Call Cells(27, 4).Select
If Not Intersect(Target, Range("$d$27")) Is Nothing Then
 Select Case Range("$d$27")
        Case "1": Macro1
        Case "2": Macro2
        Case "3": Macro3
        Case "4": Macro4
        Case "5": Macro5
    End Select
    
End If
End Sub
 
Last edited:
Upvote 0

Forum statistics

Threads
1,214,833
Messages
6,121,868
Members
449,053
Latest member
Mesh

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