Runtime Error 1004 Excel 97

M

missfitz

Hi Hoping someone can help keep getting the following error when macro
is ran. The Macro is:-

Private Sub CommandButton1_Click()
Sheets("Input Data").Select
ActiveSheet.Range("Import_Data").Select
Selection.ClearContents
Sheets("Input Data").Select
ActiveSheet.Range("A1").Select
Selection.QueryTable.Refresh BackgroundQuery:=False
Sheets("Pivot Table").Select
ActiveSheet.PivotTables("PivotTable2").RefreshTable
Sheets("Macros").Select
ActiveSheet.Range("A1").Select
End Sub


Please anyone help :cool:
 
K

K Dales

If your Import-Data range includes the entire query results range, you may be
erasing the query completely, so there is nothing left to refresh. If my
guess is correct, this would be the line highlighted when the error occurs
and you go to debug:
Selection.QueryTable.Refresh BackgroundQuery:=False

There is no need to erase a query range before refreshing. Excel will erase
the old data as part of the refresh process.
 

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

Top