Macro Excel Change color based on referenced cell

mahiney8184

New Member
Joined
Feb 18, 2010
Messages
3
I found this place that has a macro button that does something similar to what I want to do. I am able to adjust everything to suite my file perfectly so far except one thing. I am trying to get the color change to be based off of another cell, not a set value.
http://www.techonthenet.com/excel/macros/change_color.php

Based on the model that this person built... an example of what I Want to do is where it says "Case "030087"" in the code, I want it to reference Cell M14. So IF the cell the function is testing is = to cell M14, color these rows.

I know some C++ and HTML, but NO Macro. I am trying to learn, so please explain.

I tried these and they didn't work.

Case "M14"
Case Is = "M14"
Case Is = M14

Please help! Thank you.
 

Excel Facts

Add Bullets to Range
Select range. Press Ctrl+1. On Number tab, choose Custom. Type Alt+7 then space then @ sign (using 7 on numeric keypad)
Hi and welcome to the board
Code:
Case = Range("$M$14")
That said, post your code. The code you linked to may be more than you need!!

lenze
 
Upvote 0
I tried that and when I click off of it, it changes to:

Case Is = Range("$M$14")
Any advice on this would be greatly appreciated.

Thanks!
 
Upvote 0
The VBE is just making up for my laziness!!:biggrin:
Code:
Case Is = Range("$M$14")
is the correct syntax.
lenze
 
Upvote 0
I'd love to attach the excel file, but I think you can find it in the link above. With this code below, it changes the cells green, but does not change cells blue at are equal to M14. :(

Well here is what I have for the code....

Sub sort()
'
' Keyboard Shortcut: Ctrl+s
'
ActiveWindow.LargeScroll Down:=1
Range("A32").Select
ActiveWindow.LargeScroll Down:=1
Range("A65").Select
ActiveWindow.LargeScroll Down:=1
Range("A98").Select
ActiveWindow.LargeScroll Down:=1
Range("A131").Select
ActiveWindow.LargeScroll Down:=1
Range("A164").Select
ActiveWindow.LargeScroll Down:=1
Range("A197").Select
ActiveWindow.LargeScroll Down:=1
Range("A230").Select
ActiveWindow.LargeScroll Down:=1
Range("C603:L1193").Select
Selection.sort Key1:=Range("E603"), Order1:=xlDescending, Header:=xlGuess _
, OrderCustom:=1, MatchCase:=False, Orientation:=xlTopToBottom
Range("A1").Select
End Sub

Sub Update_Row_Colors()
Dim LRow As Integer
Dim LCell As String
Dim LColorCells As String
'Start at row 7
LRow = 7

'Update row colors for the first 2000 rows
While LRow < 2000
LCell = "C" & LRow
'Color will changed in columns A to K
LColorCells = "A" & LRow & ":" & "K" & LRow

Select Case Left(Range(LCell).Value, 6)

'Set row color to light blue
Case Is = Range("$M$14")
Range(LColorCells).Interior.ColorIndex = 34
Range(LColorCells).Interior.Pattern = xlSolid

'Set row color to light green
Case "030087"
Rows(LRow & ":" & LRow).Select
Range(LColorCells).Interior.ColorIndex = 35
Range(LColorCells).Interior.Pattern = xlSolid

'Set row color to light yellow
'Case "063599"
' Rows(LRow & ":" & LRow).Select
' Range(LColorCells).Interior.ColorIndex = 19
' Range(LColorCells).Interior.Pattern = xlSolid

'Default all other rows to no color
Case Else
'Rows(LRow & ":" & LRow).Select
'Range(LColorCells).Interior.ColorIndex = xlNone

End Select

LRow = LRow + 1
Wend


Range("A1").Select


End Sub
 
Upvote 0
Are your cells and M14 formatted the same?? Either Text of Number?

I have no idea what you are trying to do with your Sort sub!! Why all the selections and Scrolls when you don't use them??
lenze
 
Upvote 0

Forum statistics

Threads
1,215,029
Messages
6,122,760
Members
449,095
Latest member
m_smith_solihull

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top