Convert a Private Sub to a normal Sub

tazeo

Board Regular
Joined
Feb 15, 2007
Messages
132
Office Version
  1. 365
Platform
  1. Windows
Got a Private Sub:

Private Sub Worksheet_Activate()
On Error Resume Next
Selection.AutoFilter Field:=10, Criteria1:=Sheets("Instructions").Range("AA7").Value
Selection.AutoFilter Field:=33, Criteria1:=Sheets("Instructions").Range("AA5").Value
End Sub

How do I change it to a normal on demand macro. More to it than removing the Private bit, cause that didn't work :), so I am guessing there needs to be more at the beginning and end.

Thanks in Advance
 

Excel Facts

What is the fastest way to copy a formula?
If A2:A50000 contain data. Enter a formula in B2. Select B2. Double-click the Fill Handle and Excel will shoot the formula down to B50000.
Create a sub and name it anything you want. Then put the body of the other code in that one, i.e.

VBA Code:
Sub MyMacro()
    On Error Resume Next
    Selection.AutoFilter Field:=10, Criteria1:=Sheets("Instructions").Range("AA7").Value
    Selection.AutoFilter Field:=33, Criteria1:=Sheets("Instructions").Range("AA5").Value
End Sub
 
Upvote 0
Solution
Create a sub and name it anything you want. Then put the body of the other code in that one, i.e.

VBA Code:
Sub MyMacro()
    On Error Resume Next
    Selection.AutoFilter Field:=10, Criteria1:=Sheets("Instructions").Range("AA7").Value
    Selection.AutoFilter Field:=33, Criteria1:=Sheets("Instructions").Range("AA5").Value
End Sub
Thanks I have no idea what I was doing wrong, its working now :)
 
Upvote 0
You are welcome.
Glad I was able to help.
 
Upvote 0

Forum statistics

Threads
1,214,982
Messages
6,122,573
Members
449,089
Latest member
Motoracer88

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