help refreshing List programmatically

dhx10000

Board Regular
Joined
Jul 11, 2005
Messages
144
Hi,

I have a list in an excel worksheet that I need to refresh upon the file opening, but I need to do it through VB. The reason is because after the list is refreshed, I then need to copy some formulas in adjacent columns. I have tried doing this by "checking the appropriate values" but I am not getting accurate results.

I tried using the code below but my Refresh command is ignored. I know this because I added a new record in the source data and it did not appear in the excel sheet, upon opening the file:

Private Sub Workbook_Open()

ThisWorkbook.RefreshAll

'Range("K2") = "=HyperLinkText(B2)"
Range("K2") = "=IF(HyperLinkText(B2)=""NotAvailable.aspx?PageView=Shared"","""",HyperLinkText(B2))"
Range("K2").Select
Range("K2").Copy
Range("K2:K" & Application.WorksheetFunction.CountA(Range("A:A"))).Select
Range("K2:K" & Application.WorksheetFunction.CountA(Range("A:A"))).PasteSpecial

End Sub
 

Excel Facts

Create a Pivot Table on a Map
If your data has zip codes, postal codes, or city names, select the data and use Insert, 3D Map. (Found to right of chart icons).

Reid

Well-known Member
Joined
Oct 29, 2004
Messages
593
I assume this list is a QueryTable? If so, this structure should work (not tested):

Dim wBook as Workbook, wSheet as Worksheet, qTable as QueryTable

Set wBook=ThisWorkbook
For Each wSheet in wBook.Worksheets
For Each qTable in wSheet
qTable.Refresh
Next qTable
Next wSheet

Hope this helps.
 
Master Excel Bundle

Excel contains over 450 functions, with more added every year. That’s a huge number, so where should you start? Right here with this bundle.

Forum statistics

Threads
1,168,117
Messages
5,857,477
Members
431,882
Latest member
saaaaaaaaaaaaaaaaaaaaaa

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Top