Conditional Statement in a Macro

B

bsaxey

I have a time sheet program with a pivot table on each sheet to sum the hours
worked on each job #. Each pivot table is named pivot table 7. I have set
up a macro to update the pivot table easily. It is as follows:

Sub Update_Pivot_Table()
'
' Update_Pivot_Table Macro
' Keyboard Shortcut: Ctrl+p
'

Range("E63").Select
ActiveSheet.PivotTables("PivotTable7").PivotCache.Refresh
Range("H62").Select

End Sub

Thus, since each table is named "PivotTable7" the macro works on any of the
sheets.

I have added a pivot table to the Friday sheet that sums the entire week
("PivotTable2"). What I would like to do is add a line or two to the above
macro that checks if the active sheet is "Friday" and if it is it updates
PivotTable2, otherwise it does nothing.

Thanks in advance.
 
B

Bob Umlas, Excel MVP

Sub Update_Pivot_Table()
If Activesheet.Name = "Friday" then
ActiveSheet.PivotTables("PivotTable2").PivotCache.Refresh
Exit Sub
Else
Range("E63").Select
ActiveSheet.PivotTables("PivotTable7").PivotCache.Refresh
End If
Range("H62").Select
End Sub
 
Top