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

What is the shortcut key for Format Selection?
Ctrl+1 (the number one) will open the Format dialog for whatever is selected.
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.
 
Upvote 0

Forum statistics

Threads
1,211,528
Messages
6,102,363
Members
447,794
Latest member
rajmungur

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
Back
Top