Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
Bob Bob is offline
external usenet poster
 
Posts: 972
Default Executing a command when clicking on a tab

I need to write a macro that will automatically start whenever a user clicks
on (i.e., switches to) a certain tab (Sheet2). And all the macro needs to do
execute the PivotTable "Refresh Data" command.
Can someone kindly tell me how to do this?
Thanks in advance for any help.

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,123
Default Executing a command when clicking on a tab

Hi Bob

There is activate event for every worksheet

Copy this in a sheet module

Private Sub Worksheet_Activate()

End Sub



--

Regards Ron de Bruin
http://www.rondebruin.nl/tips.htm


"Bob" wrote in message ...
I need to write a macro that will automatically start whenever a user clicks
on (i.e., switches to) a certain tab (Sheet2). And all the macro needs to do
execute the PivotTable "Refresh Data" command.
Can someone kindly tell me how to do this?
Thanks in advance for any help.

  #3   Report Post  
Posted to microsoft.public.excel.programming
Bob Bob is offline
external usenet poster
 
Posts: 972
Default Executing a command when clicking on a tab

Hi Ron,
Thanks for the info!
Bob


"Ron de Bruin" wrote:

Hi Bob

There is activate event for every worksheet

Copy this in a sheet module

Private Sub Worksheet_Activate()

End Sub



--

Regards Ron de Bruin
http://www.rondebruin.nl/tips.htm


"Bob" wrote in message ...
I need to write a macro that will automatically start whenever a user clicks
on (i.e., switches to) a certain tab (Sheet2). And all the macro needs to do
execute the PivotTable "Refresh Data" command.
Can someone kindly tell me how to do this?
Thanks in advance for any help.


  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 857
Default Executing a command when clicking on a tab

right click on the sheet tab, click on "View Code". Then paste this:

Private Sub Worksheet_Activate()
Dim pvt As PivotTable
For Each pvt In Me.PivotTables
pvt.PivotCache.Refresh
Next pvt
End Sub



--
Hope that helps.

Vergel Adriano


"Bob" wrote:

I need to write a macro that will automatically start whenever a user clicks
on (i.e., switches to) a certain tab (Sheet2). And all the macro needs to do
execute the PivotTable "Refresh Data" command.
Can someone kindly tell me how to do this?
Thanks in advance for any help.

  #5   Report Post  
Posted to microsoft.public.excel.programming
Bob Bob is offline
external usenet poster
 
Posts: 972
Default Executing a command when clicking on a tab

Vergel,
Thanks for the help! Since there is only one PivotTable involved here, can
you tell me how to simplify your macro (since it appears that it covers
multiple PivotTables)?
Thanks again,
Bob


"Vergel Adriano" wrote:

right click on the sheet tab, click on "View Code". Then paste this:

Private Sub Worksheet_Activate()
Dim pvt As PivotTable
For Each pvt In Me.PivotTables
pvt.PivotCache.Refresh
Next pvt
End Sub



--
Hope that helps.

Vergel Adriano


"Bob" wrote:

I need to write a macro that will automatically start whenever a user clicks
on (i.e., switches to) a certain tab (Sheet2). And all the macro needs to do
execute the PivotTable "Refresh Data" command.
Can someone kindly tell me how to do this?
Thanks in advance for any help.



  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 857
Default Executing a command when clicking on a tab

Bob,

You can replace the For Loop block with this one line:

Me.PivotTables(1).PivotCache.Refresh


--
Hope that helps.

Vergel Adriano


"Bob" wrote:

Vergel,
Thanks for the help! Since there is only one PivotTable involved here, can
you tell me how to simplify your macro (since it appears that it covers
multiple PivotTables)?
Thanks again,
Bob


"Vergel Adriano" wrote:

right click on the sheet tab, click on "View Code". Then paste this:

Private Sub Worksheet_Activate()
Dim pvt As PivotTable
For Each pvt In Me.PivotTables
pvt.PivotCache.Refresh
Next pvt
End Sub



--
Hope that helps.

Vergel Adriano


"Bob" wrote:

I need to write a macro that will automatically start whenever a user clicks
on (i.e., switches to) a certain tab (Sheet2). And all the macro needs to do
execute the PivotTable "Refresh Data" command.
Can someone kindly tell me how to do this?
Thanks in advance for any help.

  #7   Report Post  
Posted to microsoft.public.excel.programming
Bob Bob is offline
external usenet poster
 
Posts: 972
Default Executing a command when clicking on a tab

Vergel,
Perfect! Thanks again for all your help.
Bob


"Vergel Adriano" wrote:

Bob,

You can replace the For Loop block with this one line:

Me.PivotTables(1).PivotCache.Refresh


--
Hope that helps.

Vergel Adriano


"Bob" wrote:

Vergel,
Thanks for the help! Since there is only one PivotTable involved here, can
you tell me how to simplify your macro (since it appears that it covers
multiple PivotTables)?
Thanks again,
Bob


"Vergel Adriano" wrote:

right click on the sheet tab, click on "View Code". Then paste this:

Private Sub Worksheet_Activate()
Dim pvt As PivotTable
For Each pvt In Me.PivotTables
pvt.PivotCache.Refresh
Next pvt
End Sub



--
Hope that helps.

Vergel Adriano


"Bob" wrote:

I need to write a macro that will automatically start whenever a user clicks
on (i.e., switches to) a certain tab (Sheet2). And all the macro needs to do
execute the PivotTable "Refresh Data" command.
Can someone kindly tell me how to do this?
Thanks in advance for any help.

Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Store data JUST entered in Activecell after clicking command button on worksheet [email protected] Excel Programming 1 August 23rd 06 04:20 AM
executing an add in Gary Keramidas Excel Programming 6 November 6th 05 09:56 PM
can I set up a sort command to happen by clicking on a table headi Aaron Excel Programming 2 November 5th 05 04:10 PM
Error when executing 'Charts.Add' command vbaprog Excel Programming 2 September 15th 05 07:09 PM
Keyboard command to replace double clicking the fill handle Pat Excel Discussion (Misc queries) 1 May 18th 05 05:50 PM


All times are GMT +1. The time now is 10:21 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"