Results 1 to 13 of 13

How to highlight a row based on a DB query result?

Threaded View

  1. #1
    Registered User
    Join Date
    09-25-2014
    Location
    Utah
    MS-Off Ver
    2010 and 2013
    Posts
    8

    How to highlight a row based on a DB query result?

    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.
    Last edited by omakler; 09-25-2014 at 07:05 PM.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Check a webpage for specific text and highlight a cell based on result
    By ks100 in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 12-12-2013, 09:56 AM
  2. Web query and query by VBA produce different result than URL in browser
    By 6StringJazzer in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 09-09-2013, 03:43 PM
  3. [SOLVED] Highlight result cells
    By Alac61 in forum Excel Formulas & Functions
    Replies: 6
    Last Post: 07-16-2013, 02:19 AM
  4. Replies: 0
    Last Post: 03-15-2006, 09:40 PM
  5. vlookup based on random result returns incorrect result
    By rickat in forum Excel Formulas & Functions
    Replies: 1
    Last Post: 12-05-2005, 09:20 AM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1