How do I auto refresh my macro?

jjt1973

New Member
Joined
Jun 8, 2011
Messages
32
I have created a template that will be used by our national sales team. I have written a macro and will be adding more. This template will need to be able to refresh everytime it is opened so that the macros automatically turn on and refresh with each scenario. Here is the current macro running:

Sub channel()
'This macro will be used to hide row 3 if not active row.

If [E2].Value = "" Then
Range("A3:I3").EntireRow.Hidden = True
End If

If [E2].Value = MN Then
Range("A3:I3").EntireRow.Hidden = True
End If

If [E2].Value = NY Then
Range("A3:I3").EntireRow.Hidden = False
End If

If [E2].Value = WI Then
Range("A3:I3").EntireRow.Hidden = False
End If

End Sub

Thanks.

JJT
 

Excel Facts

How to show all formulas in Excel?
Press Ctrl+` to show all formulas. Press it again to toggle back to numbers. The grave accent is often under the tilde on US keyboards.
Try in the ThisWorkbook module

Code:
Private Sub Workbook_Open()
Call channel
End Sub
 
Upvote 0
You would call them one after the other like this

Code:
Private Sub Workbook_Open()
Call channel
Call anothermacro
Call macro3
End Sub
 
Upvote 0
When I ran the macro on my sample worksheet it worked. However the real Macro isn't working. Can you tell me if you see an error: The actual macro is:

Sub channel()
'This macro will be used to hide row 3 if not active row.

If [E2].Value = "" Then
Range("A3:K3").EntireRow.Hidden = True
End If

If [E2].Value = Card Then
Range("A3:K3").EntireRow.Hidden = True
End If

If [E2].Value = NAS Then
Range("A3:K3").EntireRow.Hidden = True
End If

If [E2].Value = Retail Then
Range("A3:K3").EntireRow.Hidden = False
End If

If [E2].Value = "" Then
Range("A4:K4").EntireRow.Hidden = True
End If

If [E2].Value = Retail Then
Range("A4:K4").EntireRow.Hidden = True
End If

If [E2].Value = Card Then
Range("A4:K4").EntireRow.Hidden = True
End If

If [E2].Value = NAS Then
Range("A4:K4").EntireRow.Hidden = False
End If

End Sub


I have created a template that will be used by our national sales team. I have written a macro and will be adding more. This template will need to be able to refresh everytime it is opened so that the macros automatically turn on and refresh with each scenario. Here is the current macro running:

Sub channel()
'This macro will be used to hide row 3 if not active row.

If [E2].Value = "" Then
Range("A3:I3").EntireRow.Hidden = True
End If

If [E2].Value = MN Then
Range("A3:I3").EntireRow.Hidden = True
End If

If [E2].Value = NY Then
Range("A3:I3").EntireRow.Hidden = False
End If

If [E2].Value = WI Then
Range("A3:I3").EntireRow.Hidden = False
End If

End Sub

Thanks.

JJT
 
Upvote 0
You are missing quotation signs, e.g.

If [E2].Value = "Card" Then

In the VBE, Tools > Options, tick Require Variable Declaration to trap this sort of error.
 
Upvote 0
Instead of your If statements try like this

Code:
Range("A3:K3").EntireRow.Hidden = [E2].Value = ""
 
Upvote 0
That code would hide the rows but what do I need to input for the rows to autounhide based on the code above?
 
Upvote 0

Forum statistics

Threads
1,224,586
Messages
6,179,711
Members
452,939
Latest member
WCrawford

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