Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 34
Default Command Button run-time error

I have a command button on a sheet that is supposed to look through 3 sheets
and refresh pivottables. for some reason it's giving me a runtime error.

Here's the code I'm using

Sub CommandButton1_Click()

Sheets("Cert Tracking YTD Totals").Select
ActiveSheet.PivotTables("CT_Totals").RefreshTable
ActiveSheet.PivotTables("CT_Losses").RefreshTable
ActiveSheet.PivotTables("CT_Product_Totals").Refre shTable
ActiveSheet.PivotTables("CT_Product_Losses").Refre shTable

Sheets("Cert Tracking Monthly Total").Select
ActiveSheet.PivotTables("CT_Monthly_Totals").Refre shTable
ActiveSheet.PivotTables("CT_Monthly_Losses").Refre shTable

Sheets("CertTracking Monthly Prod Tot").Select
ActiveSheet.PivotTables("CT_Monthly_Prod_Totals"). RefreshTable
ActiveSheet.PivotTables("CT_Monthly_Prod_Losses"). RefreshTable

Sheets("Cert Tracking YTD Totals").Select
Range("A1:C2").Select

End Sub

Can someone tell me whats wrong? If its any help, i originally created the
code in excel 2K and i'm trying to edit it in excel97.

thanks


  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,824
Default Command Button run-time error

There's a bug in xl97 (fixed in xl2k) that deals with code called from controls
from the control toolbox toolbar that are used on a worksheet.

One fix is to change the .takefocusonclick property to false.

Another fix is to add:
activecell.activate
at the top of your code.

===
And you may want to eliminate some of the selecting:

Option Explicit
Sub CommandButton1_Click()

With Sheets("Cert Tracking YTD Totals")
.PivotTables("CT_Totals").RefreshTable
.PivotTables("CT_Losses").RefreshTable
.PivotTables("CT_Product_Totals").RefreshTable
.PivotTables("CT_Product_Losses").RefreshTable
End With

With Sheets("Cert Tracking Monthly Total")
.PivotTables("CT_Monthly_Totals").RefreshTable
.PivotTables("CT_Monthly_Losses").RefreshTable
End With

With Sheets("CertTracking Monthly Prod Tot")
.PivotTables("CT_Monthly_Prod_Totals").RefreshTabl e
.PivotTables("CT_Monthly_Prod_Losses").RefreshTabl e
End With

End Sub

and if you're updating all the pivottables in all the worksheets:

Private Sub CommandButton1_Click()
With Me.Parent
.RefreshAll
End With
End Sub


Dominique Feteau wrote:

I have a command button on a sheet that is supposed to look through 3 sheets
and refresh pivottables. for some reason it's giving me a runtime error.

Here's the code I'm using

Sub CommandButton1_Click()

Sheets("Cert Tracking YTD Totals").Select
ActiveSheet.PivotTables("CT_Totals").RefreshTable
ActiveSheet.PivotTables("CT_Losses").RefreshTable
ActiveSheet.PivotTables("CT_Product_Totals").Refre shTable
ActiveSheet.PivotTables("CT_Product_Losses").Refre shTable

Sheets("Cert Tracking Monthly Total").Select
ActiveSheet.PivotTables("CT_Monthly_Totals").Refre shTable
ActiveSheet.PivotTables("CT_Monthly_Losses").Refre shTable

Sheets("CertTracking Monthly Prod Tot").Select
ActiveSheet.PivotTables("CT_Monthly_Prod_Totals"). RefreshTable
ActiveSheet.PivotTables("CT_Monthly_Prod_Losses"). RefreshTable

Sheets("Cert Tracking YTD Totals").Select
Range("A1:C2").Select

End Sub

Can someone tell me whats wrong? If its any help, i originally created the
code in excel 2K and i'm trying to edit it in excel97.

thanks


--

Dave Peterson

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
Command Button Error - Help Needed Urgently Please Salman Excel Worksheet Functions 2 March 7th 07 10:24 AM
run-time error '91'-Close Button error ASCO IS Help Excel Discussion (Misc queries) 1 May 8th 06 04:25 PM
How to create command button to save the dates and time Ken Vo Excel Discussion (Misc queries) 6 January 5th 06 04:18 AM
How can i use a command button to validate date and time kcdonaldson Excel Discussion (Misc queries) 0 December 9th 05 04:03 PM
Run-time error on command button Phil Hageman[_3_] Excel Programming 4 November 4th 03 08:06 PM


All times are GMT +1. The time now is 07:19 PM.

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

About Us

"It's about Microsoft Excel"