Starting a macro based on cell value

  • Thread starter Thread starter Le_requin
  • Start date Start date
L

Le_requin

Hi,

I build a report in Excel with a month-selector. What I want to achieve
is that if a different month is selected the macro will be runned
automatically. The macro will update two pivots using the commands
below:

ActiveSheet.PivotTables("PivotTable2").PivotCache.Refresh
ActiveSheet.PivotTables("PivotTable1").PivotCache.Refresh

Tips are very welcome :)

Thanx,
Mike
 
If you select a different month by changing a value in a cell (or selecting
a month from a validation dropdown in xl2000 or later)

(assumes the pivot tables are on the same sheet as the cell with the month)

Assume the cell is B9

Private Sub Worksheet_Change(ByVal Target As Range)
if Target.count > 1 then exit sub
if isempty(target) then exit sub
if Target.Address = "$B$9" then
ActiveSheet.PivotTables("PivotTable2").PivotCache.Refresh
ActiveSheet.PivotTables("PivotTable1").PivotCache.Refresh
End if

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