1

My Excel sheet contains a table which fetches data from an outside source. I know I can refresh this data by right clicking the table and clicking "Refresh", but I want to be able to do this from inside my VBA code, so that I can force the data to be updated before performing certain calculations on it.

I have tried using Worksheets("Foo").Calculate as suggested by answers to similar questions, but that doesn't do the trick.

2
  • 4
    Try to record a macro and do the "Refresh". It's the best option for something like this. Commented Jan 13, 2014 at 13:54
  • +1 for record a macro! Commented Jan 13, 2014 at 14:43

1 Answer 1

2

Should be able to use QueryTable("tableName").Refresh. Here is the link to the Microsoft Developer Network page on Query Table. Check out the refresh method from there.

Sign up to request clarification or add additional context in comments.

3 Comments

This seems like it should work, but VBA can't seem to find my table by its name. That seems to be a different problem though.
If its your only table, you should be able to use QueryTable(1). If you have a lot of tables, finding its index number may be harder and you might be better off recording a macro as was suggested in the question comments.
Worksheets("Foo").Range("B2").ListObject.QueryTable.Refresh BackgroundQuery:=False seemed to be the way to find my table. Strangely it wasn't even listed in QueryTable().

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.