• Hi All

    Please note that at the Chandoo.org Forums there is Zero Tolerance to Spam

    Post Spam and you Will Be Deleted as a User

    Hui...

  • When starting a new post, to receive a quicker and more targeted answer, Please include a sample file in the initial post.

VBA refresh data [SOLVED]

mr_hiboy

Member
Hi,


I have a hidden datasheet linked to sql server table.


On my report sheet i have a button that unhides the data sheet, selects a cell and run background refresh, then hides the data sheet again.


Am I able to run the data refresh without un-hiding the sheet (so it's visible to the end user.


Code looks like this.

[pre]
Code:
Sheets("Data").Visible = True
Sheets("Data").Select
Range("E8").Select
Selection.QueryTable.Refresh BackgroundQuery:=False
Was hoping something like this would work?

ActiveWorkbook.Worksheets("Data").Range("E8").Select
Selection.QueryTable.Refresh BackgroundQuery:=False
[/pre]
I don't want to use any of the data update options as it needs to be updated on demand.


Cheers
 
The best way to find out is to give it a try! You should remove the Range.Select and Selection object from your code though because it'll error if you try to select a range which isn't on the active sheet...

[pre]
Code:
ActiveWorkbook.Worksheets("Data").Range("E8").Select
Selection.QueryTable.Refresh BackgroundQuery:=False
change to:

ActiveWorkbook.Worksheets("Data").Range("E8").QueryTable.Refresh BackgroundQuery:=False
[/pre]
 
Believe me I tried all (well not all obviously!) variations. Was nearly there!


This works a treat.


Cheers Colin, much appreciated.
 
Back
Top