• Hi All

    Please note that at the Chandoo.org Forums there is Zero Tolerance to Spam

    Post Spam and you Will Be Deleted as a User

    Hui...

  • When starting a new post, to receive a quicker and more targeted answer, Please include a sample file in the initial post.

Call macro based on cell value

ManuGrim

New Member
Hello,

I have a worksheet with 4 buttons assigned to 4 macros.
I press the button and the macro runs.

But now I want to call these macros according to a cell value.

If A1 = Daily then run macro 1
If A1 = Weekly then run macro 2
etc.

What is the code in the respective sheet for calling a macro from a module?
The code and the macros:

Code:
Private Sub RunFilter(rng As Range, IsUnique As Boolean)
With Application
    .ScreenUpdating = False
    .EnableEvents = False
    .Calculation = xlCalculationManual
   
    rng.AdvancedFilter Action:=xlFilterInPlace, Unique:=IsUnique
   
    .ScreenUpdating = True
    .EnableEvents = True
    .Calculation = xlCalculationAutomatic
End With
End Sub


Sub Daily()
Call RunFilter(Range("A1:A1000"), False)
End Sub

Sub Weekly()
Call RunFilter(Range("B6:B371"), True)
Call RunFilter(Range("B371:B736"), True)
Call RunFilter(Range("B736:B1102"), True)

End Sub

Sub Monthly()
Call RunFilter(Range("C6:C371"), True)
Call RunFilter(Range("C371:C736"), True)
Call RunFilter(Range("C736:C1102"), True)

End Sub

Sub Quarterly()
Call RunFilter(Range("D6:D371"), True)
Call RunFilter(Range("D371:D736"), True)
Call RunFilter(Range("D736:D1102"), True)
End Sub

Thank you!
 
Well, this looks familiar. :)

Here's the macro you would assign to the button.
Code:
Sub MainSub()
'This is what you assign to the button
Select Case UCase(Range("A1").Value)
    Case "DAILY"
        Call Daily
    Case "WEEKLY"
        Call Weekly
    Case "MONTHLY"
        Call Monthly
    Case "QUARTERLY"
        Call Quarterly
End Select
End Sub
 
Back
Top