Conditional Statement in a Macro

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

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.
 
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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top