Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations biv343 on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Refreshing Query Data via button click in Excel spreadsheet? 1

Status
Not open for further replies.

StevenK

Programmer
Jan 5, 2001
1,294
GB
I have a relatively simple Excel spreadsheet.
The second sheet is set to present the result sets of a query run - which is passed one parameter.
This parameter is fed from a cell in the first sheet of the same spreadsheet - and is set to 'Refresh automatically when cell value changes'.
What I want to do is now introduce a button to enable the user to refresh the data output - still based on the same entry as made in the cell on the first sheet (i.e. stock code).

How can I get this data to refresh based on a button click?
I've tried setting up a Macros behind the button that stores the value from the cell, blanks it and then resets it (to the value as stored) - but this does not seem to refresh the data on the second sheet.
The refresh only works if I go into the cell on the first sheet, modify the contents and then reset it back to it's original value.

Can anyone suggest the simplest means to do this?

Thanks in advance.
Steve
 



Have the button_click assign the cell value to itself.
Code:
With Sheets("stock code").cells(1,1)
  .value = .value
End with
assuming that the parameter is in A1.

Skip,

[glasses] When a group touring the Crest Toothpaste factory got caught in a large cooler, headlines read...
Tooth Company Freeze a Crowd! and
Many are Cold, but Few are Frozen![tongue]
 
I've introduced this code in the Macros under the button - but the data query still does not refresh.
It's only when I physically go into the cell, edit it, and then return it to it's original value that the data refreshes as required (pulling through the data as modified in the database underneath).

Can any more clues be offered?

Thanks again.

Steve
 



Code:
    Sheet1.QueryTables(1).Refresh

Skip,

[glasses] When a group touring the Crest Toothpaste factory got caught in a large cooler, headlines read...
Tooth Company Freeze a Crowd! and
Many are Cold, but Few are Frozen![tongue]
 
This seems to work a treat.
Thank you - you're a star!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top