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
 

Some videos you may like

Excel Facts

Remove leading & trailing spaces
Save as CSV to remove all leading and trailing spaces. It is faster than using TRIM().

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.
 

Watch MrExcel Video

Forum statistics

Threads
1,112,884
Messages
5,543,023
Members
410,583
Latest member
gazz57
Top