Macro Help

A

akemeny

I need to set a Macro (possibly in VBA) that will change the color of a
selected number of cells based on the text in another cell.

For example:

When A1 states - FI the row turns orange
When A1 states - ALJ the row turns green
etc.

Since I need to do this to many rows is there also a way to set this by
column rather than cell text?
 
A

Anand.V.V.N

Yea you can do it,

if you comfortable wiht coding tey using for each loop with each row, or you
can loop through cells like you doing and select the entire row and then
change the color of the row.

I guess it might work
Anand.V.V.N
 
R

Rick Rothstein

This macro will do what you asked...

Sub ChangeRowColors()
Dim C As Range
For Each C In Selection
Select Case UCase(C.Value)
Case "FI"
ColorVal = 45 ' ColorIndex for Orange
Case "ALJ"
ColorVal = 50 ' ColorIndex for a shade of Green
'
' Add additional Case statements for your other
' codes here (always use upper case for the codes).
'
Case Else
ColorVal = xlNone
End Select
C.EntireRow.Interior.ColorIndex = ColorVal
Next
End Sub

Just add the additional Case statements where indicated. The numbers that
are being assigned inside the Case statements are ColorIndex values.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top