Run a macro based on text in a cell?

camhall22

New Member
Joined
Feb 2, 2012
Messages
19
Hello

Im new to this and was hoping for some help/advice. What I would like to do it run a macro when specific text is entered into a specific cell. This is for a template I am making.

For example when a user entered the words "None" or "Zero" into cell D4 - the macro is run automatically. If any other value is entered, do nothing

Any help would be much appreciated
 
My mistake:
Code:
Private Sub Worksheet_Change(ByVal Target As Range)
If Not Intersect(Target, Range("B3")) Is Nothing Then
    Range("51:55").EntireRow.Hidden = (Range("B3").Value <> "Tower")
End If
End Sub
 
Last edited:
Upvote 0

Excel Facts

Do you hate GETPIVOTDATA?
Prevent GETPIVOTDATA. Select inside a PivotTable. In the Analyze tab of the ribbon, open the dropown next to Options and turn it off
Thanks so much! Incredible help!

My mistake:
Code:
Private Sub Worksheet_Change(ByVal Target As Range)
If Not Intersect(Target, Range("B3")) Is Nothing Then
    Range("51:55").EntireRow.Hidden = (Range("B3").Value <> "Tower")
End If
End Sub
 
Upvote 0
You have been an amazing help. I am trying to learn from what you did but honestly, I can't understand it. I need to modify the macro so that IF B3 = "Tower" unhide rows 51-55 IF B3 = "Gallery" unhide rows 51-55 IF B3 = "Ruther" unhide rows 62-69 IF B3 = ANYTHING ELSE, leave those rows hidden.

Can you help?

My mistake:
Code:
Private Sub Worksheet_Change(ByVal Target As Range)
If Not Intersect(Target, Range("B3")) Is Nothing Then
    Range("51:55").EntireRow.Hidden = (Range("B3").Value <> "Tower")
End If
End Sub
 
Upvote 0
You'll need different structure for that:
Code:
Private Sub Worksheet_Change(ByVal Target As Range)
If Not Intersect(Target, Range("B3")) Is Nothing Then
    Select Case Range("B3").Value
        Case "Tower", "Gallery"
            Range("51:55").EntireRow.Hidden = False
            Range("62:69").Entirerow.hidden = True
        Case "Ruther"
            Range("51:55").EntireRow.Hidden = True
            Range("62:69").Entirerow.hidden = False
        Case Else
            Range("51:55").EntireRow.Hidden = True
            Range("62:69").Entirerow.hidden = True
      End Select
End If
End Sub
 
Upvote 0
You are amazing. I wish I could understand it but it works great. Thank you so much!

You'll need different structure for that:
Code:
Private Sub Worksheet_Change(ByVal Target As Range)
If Not Intersect(Target, Range("B3")) Is Nothing Then
    Select Case Range("B3").Value
        Case "Tower", "Gallery"
            Range("51:55").EntireRow.Hidden = False
            Range("62:69").Entirerow.hidden = True
        Case "Ruther"
            Range("51:55").EntireRow.Hidden = True
            Range("62:69").Entirerow.hidden = False
        Case Else
            Range("51:55").EntireRow.Hidden = True
            Range("62:69").Entirerow.hidden = True
      End Select
End If
End Sub
 
Upvote 0
Hi, I'm trying to run the code shown below to automatically run a macro. I have a IF formula in cell D3, which will change the value to "1" if certain conditions apply. But when cell D3 turns to "1" the macro won't run unless I actually click into cell D3 and press tab/enter, but I need it to run automatically. When I click into cell D3 the Macro does run, so I think the code is correct, but it just seems like it won't recognize that D3 turned to "1" unless I click into cell D3. Anybody know how I can get this to run automatically? Thanks in advance for your time and help!!


Code:
Private Sub Worksheet_Change(ByVal Target As Range)
 If Not Intersect(Target, Range("D3")) Is Nothing Then
 If Target.Value = 1 Then Application.Run "CopySymAndQuantity"
End If
 End Sub
 
Last edited by a moderator:
Upvote 0

Forum statistics

Threads
1,214,911
Messages
6,122,198
Members
449,072
Latest member
DW Draft

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