Excel Macro: Run Macro Based on a cell value

rorymcc

New Member
Joined
Jul 7, 2017
Messages
9
Hi I'm trying to run a macro based on another cell value. I simply want to hide rows based on a dropdown value from another cell. Is this possible. I have working code that is hiding rows, but it is not being triggered when the value is selected I have to manually run the macro. Could someone help me?

Code:

Private Sub worksheet_change(ByVal target As Range)
Set target = Range("B1")
If target.value = "Delete" Then
Call Macro1
End If
End Sub


Sub Macro1

If Range("B1").Value="Delete" Then
Rows("3:4").EntireRow.Hidden = True .......etc


The sub macro1 is working but not being triggered by the private sub on the worksheet
 
If you had wanted to do it the original way, I think the issue is that your procedures are looking to be passed a range value, and you aren't doing that.
It might work if you try:
Code:
[COLOR=#333333]Private Sub Worksheet_Change(ByVal Target As Range)[/COLOR]
[COLOR=#333333]    My_Sub_A Target([/COLOR][COLOR=#ff0000]Target[/COLOR][COLOR=#333333])[/COLOR]
[COLOR=#333333]    My_Sub_B Target([/COLOR][COLOR=#ff0000]Target[/COLOR][COLOR=#333333])[/COLOR]
[COLOR=#333333]End Sub[/COLOR]
 
Upvote 0

Excel Facts

Copy a format multiple times
Select a formatted range. Double-click the Format Painter (left side of Home tab). You can paste formatting multiple times. Esc to stop

Forum statistics

Threads
1,214,376
Messages
6,119,178
Members
448,871
Latest member
hengshankouniuniu

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