Excel Function in VBA

melforce

New Member
Joined
Mar 18, 2015
Messages
5
Actually i want to make the button call CreatePivotTable in accordance with month for today,
So if today month is january, then the button do

Code:
    Call CreatePivotTableJan
    Call CreatePivotTable2Jan
    Call AutoFit

I confuse how to make it, anyone can help?

Code:
Private Sub CommandButton1_Click()

If Month(today()) = 1 Then
    Call CreatePivotTableJan
    Call CreatePivotTable2Jan
    Call AutoFit
    
If Month(today()) = 2 Then
    Call CreatePivotTableFeb
    Call CreatePivotTable2Feb
    Call AutoFit
    
If Month(today()) = 3 Then
    Call CreatePivotTableMar
    Call CreatePivotTable2Mar
    Call AutoFit

Else
    Call CreatePivotTableApr
    Call CreatePivotTable2Apr
    Call AutoFit

End Sub
 

Excel Facts

Shade all formula cells
To shade all formula cells: Home, Find & Select, Formulas to select all formulas. Then apply a light fill color.
TRY BELOW

Code:
Private Sub CommandButton1_Click()

If Month(Now()) = 1 Then
    Call CreatePivotTableJan
    Call CreatePivotTable2Jan
    Call AutoFit
    
ElseIf Month(Now()) = 2 Then
    Call CreatePivotTableFeb
    Call CreatePivotTable2Feb
    Call AutoFit
    
ElseIf Month(Now()) = 3 Then
    Call CreatePivotTableMar
    Call CreatePivotTable2Mar
    Call AutoFit

Else
    Call CreatePivotTableApr
    Call CreatePivotTable2Apr
    Call AutoFit
END IF
End Sub
 
Upvote 0

Forum statistics

Threads
1,214,588
Messages
6,120,412
Members
448,960
Latest member
AKSMITH

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