+ Reply to Thread
Results 1 to 11 of 11

Cell Color as Variable

  1. #1
    Registered User
    Join Date
    04-05-2018
    Location
    Abbotsford, Canada
    MS-Off Ver
    2013
    Posts
    6

    Question Cell Color as Variable

    I am playing with the idea of checking a cell's value against a reference table. In my original document it has to be a table because the number of rows is always changing. I have played with two simple FOR loops, but it seems that I have not been able to declare the color of the reference cell as a variable. I have been able to check the value of the cell by using:

    If inputCell.Value = Cells(i, 1) Then inputCell.Interior.Color = RGB(255, 0, 0) and it changes the according cells.

    I need the final program to cycle through the list in the reference table ("Table1") and pull the Interior.Color of each cell IF inputCell.Value = Cells(i, 1) ELSE move on to the next row.

    My final project is a bit more complicated so I decided to boil it down into a simple one worksheet document. Does anyone know a simple (or simpler) solution to validate EACH cell in a table against EACH cell in another table?

    Thanks in advance
    Attached Files Attached Files

  2. #2
    Forum Expert
    Join Date
    08-12-2012
    Location
    Sydney, Australia
    MS-Off Ver
    Excel 2010
    Posts
    5,636

    Re: Cell Color as Variable

    having trouble understanding what is your expected output is
    did you want table 2 to be colored in with the reference of table1?
    If you are satisfied with the solution(s) provided, please mark your thread as Solved.
    Select Thread Tools-> Mark thread as Solved. To undo, select Thread Tools-> Mark thread as Unsolved.

  3. #3
    Registered User
    Join Date
    04-05-2018
    Location
    Abbotsford, Canada
    MS-Off Ver
    2013
    Posts
    6

    Re: Cell Color as Variable

    Yes. I want to see if Cell(i, j).Value from Table2 matches Cell(i, 1) from Table1. If it finds a matching value, I want Table1 cells' color to be copied over to the destination cell in Table2.

  4. #4
    Forum Guru Winon's Avatar
    Join Date
    02-20-2007
    Location
    East Rand, R.S.A.
    MS-Off Ver
    2010
    Posts
    6,113

    Re: Cell Color as Variable

    Hello CBrechin,

    You could apply Conditional Formatting as shown in the attached sample Workbook. It is almost always better to use built in Excel features, rather than reverting to VBA.

    Regards.
    Attached Files Attached Files
    Please consider:

    Be polite. Thank those who have helped you. Then Click on the star icon in the lower left part of the contributor's post and add Reputation. Cleaning up when you're done. If you are satisfied with the help you have received, then Please do Mark your thread [SOLVED] .

  5. #5
    Registered User
    Join Date
    04-05-2018
    Location
    Abbotsford, Canada
    MS-Off Ver
    2013
    Posts
    6

    Re: Cell Color as Variable

    I realize this. But my project is much larger than this sheet. I have conditional formatting already for the one worksheet. But because you can not change conditional formatting to match a dynamic range of values, I have to use VBA for a listening Sub to push the new color over from one table to the next.

    I have to find a way to do it with VBA. Thanks for the suggestion, I had explored that option extensively before coming to the conclusion that VBA was the most effective.

  6. #6
    Forum Expert
    Join Date
    08-12-2012
    Location
    Sydney, Australia
    MS-Off Ver
    Excel 2010
    Posts
    5,636

    Re: Cell Color as Variable

    ok the way you had the syntax was a bit ambigious
    try this solution


    Please Login or Register  to view this content.
    Attached Files Attached Files

  7. #7
    Registered User
    Join Date
    04-05-2018
    Location
    Abbotsford, Canada
    MS-Off Ver
    2013
    Posts
    6

    Re: Cell Color as Variable

    Wow that works fantastically! Sorry for my ambiguity, I am still learning how to better phrase my questions.

    I like what you did with the tbl variable. Smart idea.

    Why do you use End If at the end of the Sub?

    Thanks again.

  8. #8
    Forum Expert
    Join Date
    08-12-2012
    Location
    Sydney, Australia
    MS-Off Ver
    Excel 2010
    Posts
    5,636

    Re: Cell Color as Variable

    hhmmm

    You need to end if, if your IF statement runs more than one line

    Please Login or Register  to view this content.
    ^ no end if required

    Please Login or Register  to view this content.
    end if required to close the IF statement

  9. #9
    Forum Guru Winon's Avatar
    Join Date
    02-20-2007
    Location
    East Rand, R.S.A.
    MS-Off Ver
    2010
    Posts
    6,113

    Re: Cell Color as Variable

    @ humdingaling,

    Nice work.!

    Little touch up?

    Regards
    Attached Files Attached Files

  10. #10
    Forum Expert
    Join Date
    08-12-2012
    Location
    Sydney, Australia
    MS-Off Ver
    Excel 2010
    Posts
    5,636

    Re: Cell Color as Variable

    nice touch

    Even went to the trouble of coloring in the font color

  11. #11
    Forum Guru Winon's Avatar
    Join Date
    02-20-2007
    Location
    East Rand, R.S.A.
    MS-Off Ver
    2010
    Posts
    6,113

    Re: Cell Color as Variable

    Hello CBrechin,

    You are welcome, thank you for the Rep+. Much appreciated!

    Regards.

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. Change cell format (cell color+font color) based on color of another cell
    By Dedaluss in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 06-30-2017, 03:27 AM
  2. Variable placement linked data, including CELL COLOR...?
    By fourmurphys in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 04-13-2016, 04:22 PM
  3. Variable placement linked data, including CELL COLOR...?
    By fourmurphys in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 04-13-2016, 04:19 PM
  4. Variable placement linked data, including CELL COLOR...?
    By fourmurphys in forum Excel Formulas & Functions
    Replies: 2
    Last Post: 04-13-2016, 04:19 PM
  5. Replies: 4
    Last Post: 12-29-2013, 11:41 PM
  6. Replies: 0
    Last Post: 08-31-2011, 09:44 AM
  7. how to extract a variable from a cell based on cell color
    By luv2glyd in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 09-05-2010, 09:46 AM

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