Hi Again:
I'm using XL97-SR2. I have 3 sets of code associated with 3 cmdClick buttons that I want to combine into 1 set and 1 button so the user only has to click one button:
BUTTON1 - Refreshes a query & returns data to Columns A:E;
BUTTON2 - Clears F3:G6500 & copies the equations in F2:G2 down the length of the query Table (cols A:E);
BUTTON3 - Refreshes a PT which gets its data from the query Table plus columns F & G.
All 3 Buttons operate, independently, as they should. First, I try to combine 1&2 into cmdClick1 (The indented code is from Click2):
Private Sub CommandButton1_Click()
Dim LastRow As Long
Worksheets("All").Range("A3:E5000").ClearContents
Worksheets("All").Range("A1:A1").QueryTable.Refres h
Range("F3:F3").Select
****LastRow = Application.CountA(ActiveSheet.Range("D"))
****Range("F3:G6500").ClearContents
****Range("F2:G2").Select
****Selection.AutoFill Destination:=Range("F2:G" & LastRow)
****Range("K6:K6").Select
End Sub
IT NOW WILL NOT RUN -- It stops at the "Selection.AutoFill" line with a nondescript error message. I think what is happening is that the query completes but it takes a few seconds for the data to appear in the WS & the error message appears before this happens. So, I tried inserting;
For I= 1 to 100
DoEvents
Next i
after the "Range("F3:F3").Select" but it did not help. SO,THIS IS MY 1st PROBLEM.
Next, I tried moving the CommandButton3 code into CommandButton2 code as follows:
Private Sub CommandButton2_Click()
Dim LastRow As Long
LastRow = Application.CountA(ActiveSheet.Range("D"))
Range("F3:G6500").ClearContents
Range("F2:G2").Select
Selection.AutoFill Destination:=Range("F2:G" & LastRow)
Range("K6:K6").Select
****'Private Sub CommandButton3_Click()
****Set pvtTable=Worksheets("Sheet1").Range("k6").PivotTab le
****pvtTable.RefreshTable
****Range("H1").Value = Now()
End Sub
It balks again, this time at the "pvtTable.RefreshTable" line with another nondescript error message.
This is got me hog-tied. Any help will be appreciated.
I reported similar problems in Post#: 43267.
Regards and End Sub,
Stephen
<img src=/S/grovel.gif border=0 alt=grovel width=31 height=23>

"))


