I am a little unclear as to how you are executing your SQL query. The only experience I have using SQL in VBA is to interface to an Access database. This interface requires you to build your query as a text string, then submit it using an established connection. It has been a while since I've done that but the code would look something like this. You have to execute the VLOOKUP as a WorksheetFunction (there is no VLOOKUP function native to VBA) and take the result and incorporate that into your query. The way you have written it just uses the VLOOKUP formula as a string rather than actually calling it, so that's what you are going to get in your result.
I haven't built a reference application to test this out, but hopefully this gives us a basis for further discussion to find out what you really need:
Dim varConnection as String
Dim varSQL as String
varConnection = "ODBC; DSN=MS Access Database;DBQ=C:\test.mdb; Driver={Driver do Microsoft Access (*.mdb)}"
' Build the query based on the SQL in your post
' Note that your quotes around Internal Team Data were actually repeated
' single quotes, but that wasn't evident from the font in your post (please use code tags).
' I changed them to double quotes.
varSQL = "SELECT roi.ganumber, roi.cont_eff_date," & _
WorksheetFunction.VLOOKUP(A2,"Internal Team Data"!A:D,4,FALSE) & _
"FROM rpsc_opp_install roi"
' Submit the query and dump result to A1
With ActiveSheet.QueryTables.Add(Connection:=varConnection, Destination:=Range("A1"))
.CommandText = varSQL
.Name = "Query-39008"
.Refresh BackgroundQuery:=False
End With
Bookmarks