function to change a specific cells range color depending on a text

jorgefilemon

New Member
Joined
May 9, 2014
Messages
9
j5q7tc
j5q7tc



hi guys,

what i want to do is to change the color of a specific cells range depending on the text content on the cell column called ubi, so far this is what i have written, i dont know VBA though. im missing how to write the range on the specifi cells I guess.

Function apa()

If (cell.Value = "apa" Or cell.Value = "apa mesa") Then
Range( U?:AJ? ).Interior.Color = RGB(192, 192, 192)
ElseIf (cell.Value = "mesa") Then
Range( U?:AJ?).Interior.Color = RGB(153, 204, 0)
Else
Range( U?:AJ? ).ColorIndex = 0

End function

Captura.png
 
Last edited:

Excel Facts

Ambidextrous Undo
Undo last command with Ctrl+Z or Alt+Backspace. If you use the Undo icon in the QAT, open the drop-down arrow to undo up to 100 steps.
j5q7tc
j5q7tc



hi guys,

what i want to do is to change the color of a specific cells range depending on the text content on the cell column called ubi, so far this is what i have written, i dont know VBA though. im missing how to write the range on the specifi cells I guess.

Function apa()

If (cell.Value = "apa" Or cell.Value = "apa mesa") Then
Range( U?:AJ? ).Interior.Color = RGB(192, 192, 192)
ElseIf (cell.Value = "mesa") Then
Range( U?:AJ?).Interior.Color = RGB(153, 204, 0)
Else
Range( U?:AJ? ).ColorIndex = 0

End function

Captura.png

I'd recommend using conditional formatting to change to change the color of text (or the cell) if it contains a specific content.
 
Upvote 0
I'd recommend using conditional formatting to change to change the color of text (or the cell) if it contains a specific content.


i cant make conditional formatting to work this way, as it only changes the colors within the cell where the rule is applied.
 
Upvote 0

Forum statistics

Threads
1,215,176
Messages
6,123,464
Members
449,100
Latest member
sktz

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