I am new to programming Excel and could use some help. I have read a few thing but not able to piece it together.
I have a worksheet that has a list of values, say in Column A. I want to query a SQL database to see if that value exists in the database and if it does highlight the row for each row. Ideally it would do this after entering the number and moving to the next row. I could really use the help as I am at a loss on where to go. Do I do this in VBA, macro, ...?
My sql statement in a macro looks like this.
For each inv in Range("A1:A" & Cells(Rows.Count,1).End(xlUp).Row)
sql = "Select 1 from table Where x= "& inv.value
With ... <this part would highlight the appropriate row based on if the resultset returned anything for that row - Not really sure where to begin for this>
End With
next inv
This is as far as I have been able to get to and not sure where to go from here. From what I understand this part works fine in getting the information from the DB, just not sure how to highlight the rows that have a returned value.
Example:
If A had the following
1154
1155
1156
1157
The query returns a 1 for 1154 and 1157 and NULL for 1155 and 1156. How would I now go about highlighting 1154 and 1157? I figure I could have the results enter the 1 in the given row in column B and have a highlighting rule but not sure how to do that either.
I tried
With ActiveSheet.QueryTables.Add(Connection:=connstring, Destination:=Range("B1:B" & Cells(Rows.Count,1).End(xlUp).Row), Sql:=sqlstring).Refresh
End With
but it just enters the results to Row 2 starting in column B.
Hope this all makes sense.
Bookmarks