Closed Thread
Results 1 to 3 of 3

Return a cell value as well as it's background color

  1. #1
    Registered User
    Join Date
    12-01-2010
    Location
    Pittsburgh, PA
    MS-Off Ver
    Excel 2007
    Posts
    11

    Return a cell value as well as it's background color

    Hello all,

    I have a table with the columns: id, company and year, eg:
    2 Dell 1996
    2 Microsoft 1999
    5 Apple 1997
    5 Oracle 1999
    5 Amazon 2000

    I want to look in this table for a certain id and a certain year (some ids show up multiple times with multiple companies and years, I want hte first instance of an id and year match), and then print the company in the appropriate cell in another 2d table where the left column is just IDs and the row at the top is years.

    1995 1996 1997 1998 1999 2000
    2 Dell Microsoft
    5 Apple Oracle Amazon
    I have done this successfully using the following function, but now I also want it to return the color of the cell, not just its value.
    ---
    Function PrintCompany(ID As Long, Year As Integer, cells As Range)
    Dim Pos As Range, count As Integer
    count = 1
    Set Pos = cells(1, 1)
    Do While (count <= cells.Rows.count)
    PrintCompany = ""
    If (ID = Pos.Value And Pos.Offset(0, 2).Value = Year) Then
    PrintCompany = Pos.Offset(0, 1).Value
    'ActiveCell.Interior.ColorIndex = pos.Offet(0, 1).Interior.ColorIndex <- not working
    'currentcell.Interior.Color = pos.Offset(0, 1).Interior.Color <- not working
    Exit Do
    Else: PrintCompany = ""
    End If
    count = count + 1
    Set Pos = cells(count, 1)

    Loop

    End Function

    --------

    I have tried calling a sub from the function to do just that but I don't know how to do it right. I have tried all sorts of other things to no avail. Any help would be appreciated.

  2. #2
    Forum Expert Paul's Avatar
    Join Date
    02-05-2007
    Location
    Wisconsin
    MS-Off Ver
    2016/365
    Posts
    6,885

    Re: Return a cell value as well as it's background color

    Please edit your post to add CODE tags around your code. Instructions for doing so can be found in the Forum Rules, for which there is a link in my signature below.

  3. #3
    Forum Expert Paul's Avatar
    Join Date
    02-05-2007
    Location
    Wisconsin
    MS-Off Ver
    2016/365
    Posts
    6,885

    Re: Return a cell value as well as it's background color

    This is a duplicate post and as such does not comply with Rule 5 of our forum rules. This thread will now be closed, you may continue in your other thread.

    http://www.excelforum.com/excel-gene...and-color.html

    Thread Closed.

Closed Thread

Thread Information

Users Browsing this Thread

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

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