Need to add If statement in code

MightyQuinn

Board Regular
Joined
Dec 28, 2007
Messages
152
I have this code (which works perfectly), now I want to add in an If statement to it (in red below).

It should check to see IF a cell = "text" then it runs a macro, ELSEIF cell = "other text" it runs another macro and ELSE will do nothing.

Here is my code:
Code:
Private Sub Worksheet_Change(ByVal Target As Range)
    If Not Intersect(Target, Range("W39")) Is Nothing Then
On Error GoTo Error:
    Select Case Target.Value
        Case "10 x 10"
        Application.EnableEvents = False
            Macro4
[COLOR="Red"]IF AH15 = "IM130 Rev A"  
Macro5
Elseif AH15= "IM100 Rev B" 
Macro6
Else will do nothing[/COLOR]
            GoTo Finish
        Case "10 x 7.5"
        Application.EnableEvents = False
            Macro1
            GoTo Finish
        Case "10 x 5"
        Application.EnableEvents = False
            Macro2
            GoTo Finish
        Case "10 x 2.5"
        Application.EnableEvents = False
            Macro3
            GoTo Finish
        Case Else
            MsgBox "Unexpected value, please select again."
        Application.EnableEvents = False
            GoTo Finish:
        End Select
    End If
Finish:
    Application.EnableEvents = True
    Exit Sub
Error:
    MsgBox "Macro not found!"
End Sub

Note: Only need to add the code in red. And I have the simple macros working already.
 

Excel Facts

Links? Where??
If Excel says you have links but you can't find them, go to Formulas, Name Manager. Look for old links to dead workbooks & delete.
Code:
If AH15 = "IM130 Rev A" Then
Macro5
ElseIf AH15 = "IM100 Rev B" Then
Macro6
Else
'will do nothing
End If

HTH
 
Upvote 0
It doesnt work, but I think its because I'm adding it in with the other code. Is there another place I can add this code so it runs automatically just as my code does? Maybe add it below the code I have on the same sheet?
 
Upvote 0
It doesnt work, but I think its because I'm adding it in with the other code. Is there another place I can add this code so it runs automatically just as my code does? Maybe add it below the code I have on the same sheet?

A little more information on how it doesn't work?
do you get an error
does it stop with an error on a particular line?
 
Upvote 0
Not really sure how to step through (F8?) (also tryed tools, macro5, step into and it turns yellow?), but when I run the macro5 separately it works just not in my previous code. I also just typed the code for macro5 into the If statement and it still does not so anything. I mean it will run "macro4" just before the if statement but will not run macro5 in the if statement.
 
Upvote 0
so it sounds like perhaps the if statement before macro5 was false - yes/no?

and yes the StepInto and F8 steps line by line in the macro.
 
Upvote 0

Forum statistics

Threads
1,214,975
Messages
6,122,538
Members
449,088
Latest member
RandomExceller01

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