RefreshAll Data with VBA

J

JasonSelf

Well, this should be my last question for a little while. I need t
create a button that refreshes all data on a specific sheet (we wil
call it sheet1) I found this Worksheets(2).RefreshAll that is suppose
to do just that. I just don't understand exactly how I specify m
worksheet. The 2 is not the name of any of my sheets but doing
little searching I found that it may be the Index property....I do no
understand how I can determine the index property if that is indeed th
case.

Thanks for your help as always, any input would be greatl
appreciated.

Jason Sel
 
T

Tom Ogilvy

I don't know where you found that code, but it raises an error for me. The
RefreshAll method is a method of the workbook, not the worksheet.

If it would work, you would use Worksheets("Sheet2").RefreshAll
to refer to a worksheet named Sheet2

If you have querytables on the sheet

Dim qt as QueryTable
for each qt in Worksheets("sheet2").QueryTables
qt.Refresh BackgroundQuery:=False
Next

for pivot Tables
Dim pt as PivotTable
for each pt in Worksheets("Sheet2").PivotTables
pt.RefreshTable
Next

Or if you just want to refresh the whole workbook

Workbooks("Myfile.xls").RefreshAll
 
J

JasonSelf

I actually got that sippet of code from searching refreshall in the vb
help. Thanks for the help...doing that worked perfectly, Thanks
 

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