Consulting

Results 1 to 2 of 2

Thread: Solved: Iserror + Vlookup to color cells where value is present in a list

  1. #1

    Solved: Iserror + Vlookup to color cells where value is present in a list

    Hi, All.

    So, I know what I want to do, have an idea how to do it, but not sure where to start.

    I have a list of stores that are included in a lobby display program which includes store numbers.

    I also have a list of order adjustment recommendations that my team uses to adjust orders, which also includes store numbers. But, not all stores included in the recommendation list have lobby displays.

    What I want to do is color the cells containing the store numbers in the recommendation list that are found in the lobby display list, and leave the ones that are not in the lobby display list, and I want this to happen as a part of the recommendation list preparation macro.

    I have thought a way to do this is create a loop that starts on the first line of the recommendation list, and goes down until the store number cell is blank, that would look a little like this (forgive the half code/half sentence format):

    Do Until store# = ""

    If(iserror(vlookup(store#, lobby display range, etc) then loop counter = loop counter + 1

    Else: Range(store#) Color = blue, loop counter + 1

    Loop

    Any help on how to actually code this would be hugely appreciated - I know how to reference the relevant cell locations, just need to know how the iserror and vlookup check would look in VBA.

    Thanks a ton in advance - please let me know if there's anything further required for clarification.

    Cheers!
    Nate.

  2. #2
    Ok, so after a little more messing around, I figured it out:

    [vba]Sub HighlightFeatureDisplayStores()
    Dim varRow As Long

    varRow = 2

    Sheets("Truck Report").Select

    Range("B2").Select

    Do While Cells(varRow, 2).Value <> ""

    If Not IsError(Application.VLookup(Range("B" & varRow), Sheets("FD Stores").Range("A:A"), 1, 0)) Then
    Range("B" & varRow).Interior.ColorIndex = 7
    varRow = varRow + 1

    Else: varRow = varRow + 1

    End If

    Loop


    End Sub[/vba]

    Should have messed around a little longer before bugging you all...sorry about that!

    Thanks anyway...

Posting Permissions

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