Q:

VBA vlookup on table produced by Connection String

Part of a macro I have refreshes a connection to SQL (which is running a query to place two columns of data in a tab) and does a vlookup with data (different tab) in an existing column on the table produced by the query.
'Refreshing Connection named Query From Warehouse
ActiveWorkbook.Connections("Query from Warehouse").Refresh

Range("M2").Select
ActiveCell.FormulaR1C1 = _
    "=IF(ISNA(VLOOKUP([@polid],RwlID,2,FALSE)),[@polid],VLOOKUP([@polid],RwlID,2,FALSE))"

The table created by the query being named RwlID
Problem I'm having is that the vlookup is only working for the data that was already in RwlID to begin with. I thought maybe this was happening because it was moving on before the connection finished refreshing so I moved the two pieces of the code either side of other queries in the macro (that take much longer to run) but that didn't help.
Now I'm thinking Excel still thinks RwlID is only of certain length. So for example it was 400 rows yesterday and extends to 450 today, my lookup is only going to 400. 
(In the Macro only, as when I manually enter the lookup again after the macro has run the cells populate as I had expected)
So I tried adding (RlwID is in sheet 5):
    sheets(5).ListObjects(1).Name = "RwlID"

Thinking it might rename the table of 450 as RwlID as opposed to the 400, but wasn't successful.
Any ideas why it's not working? How to fix it?
Thanks.

A:

Issue is that the code is continuing while the query is still refreshing, so the vlookup has been performed before there is data to search. Fix is to disable background refresh: Data -> Connectons -> Properties -> untick 'enable background refresh'

