+ Reply to Thread
Results 1 to 3 of 3

vlookup based on cell color

Hybrid View

  1. #1
    Registered User
    Join Date
    06-23-2009
    Location
    ohio
    MS-Off Ver
    Excel 2003
    Posts
    1

    vlookup based on cell color

    I am creating a staffing request spreadsheet for my managers to use.

    In the first worksheet Column A contains a list of employee names. When the managers dbl click the names of the employees they are recalling for work (or laying off), the cell will turn green.

    From there, I would like to look up the corresponding address associated with the names in the cells that have been turned green. (names and address are located on second worksheet in same workbook)

    I want to copy both the name and address onto a third worksheet. (from that third sheet, I am going to generate mail-merge form letters in Word). But I only want the third sheet to contain the names/addresses of the cells that are colored green on the first sheet.

    Thanks for your help.
    Kolette

  2. #2
    Valued Forum Contributor
    Join Date
    02-04-2009
    Location
    Texas
    MS-Off Ver
    Excel 2016
    Posts
    667

    Re: vlookup based on cell color

    It is probably not as elegant as you like - I would probably add a column in front of the names, have the mgrs put a 1 if they are calling in the employee. Now you can have formula if a#>0,...

  3. #3
    Forum Guru
    Join Date
    08-05-2004
    Location
    NJ
    MS-Off Ver
    365
    Posts
    13,582

    Re: vlookup based on cell color

    First, as Crimedog suggested, insert a blank column B
    Then I would do this in two parts. First write a worksheet event code for doubleclick (paste this code into the worksheet vba window)
    Private Sub Worksheet_BeforeDoubleClick(ByVal Target As Range, Cancel As Boolean)
    If Target.Column > 1 Then Exit Sub
    If Target.Interior.ColorIndex > 0 Then      'if the target already is colored
        Target.Interior.ColorIndex = -4142      'remove the color
        Target.Offset(0, 1) = ""                'clear the cell in col B
    Else
        Target.Interior.ColorIndex = 14         'set the background color to green
        Target.Offset(0, 1) = 1                 'set the cell in B to 1
    End If
    
    End Sub
    This code will color your cell (adjust the color index for a specific color (1 to 56 I believe) and will put a 1 into column B of that row.
    Then in Column C and over, you can use VLOOKUP function inside an IF statement to look in Column B, if there's a 1, then do a vlookup, if not, keep blank. If you need help with VLOOKUP, let us know.
    ChemistB
    My 2?

    substitute commas with semi-colons if your region settings requires
    Don't forget to mark threads as "Solved" (Edit First post>Advanced>Change Prefix)
    If I helped, Don't forget to add to my reputation (click on the little star at bottom of this post)

    Forum Rules: How to use code tags, mark a thread solved, and keep yourself out of trouble

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

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