Copy conditonal formatting colors

S

salgud

I have a spreadsheet I recreate each week to track what projects I work on.
Part of it uses conditional formatting. I'd like to be able to copy the
colors from the conditional formtting in cell A1 to be used with different
formulas in other cells. Does anyone know how to copy those colors over?
Thanks in advance.
 
A

Alan

I have a spreadsheet I recreate each week to track what projects I work on.
Part of it uses conditional formatting. I'd like to be able to copy the
colors from the conditional formtting in cell A1 to be used with different
formulas in other cells. Does anyone know how to copy those colors over?
Thanks in advance.

I am assuming that you are copying colors from the conditional
formatting in cell A1 to be used with other conditional formatting ...
Try:

Sub CopyColors

Dim FCondition as FormatCondition
Dim i as integer

i=1
For Each FCondition in Activecell.FormatConditions
With ActiveCell.FormatConditions(i).Font
.ColorIndex=Range("A1").FormatConditions(i).Font.ColorIndex
End With
i=i+1
Next

end sub

Before you run this sub, select the cell whose conditions are to be
changed. If there are more conditions in the selected cell than in
cell A1 this simple code will fail.
 
S

salgud

I am assuming that you are copying colors from the conditional
formatting in cell A1 to be used with other conditional formatting ...
Try:

Sub CopyColors

Dim FCondition as FormatCondition
Dim i as integer

i=1
For Each FCondition in Activecell.FormatConditions
With ActiveCell.FormatConditions(i).Font
.ColorIndex=Range("A1").FormatConditions(i).Font.ColorIndex
End With
i=i+1
Next

end sub

Before you run this sub, select the cell whose conditions are to be
changed. If there are more conditions in the selected cell than in
cell A1 this simple code will fail.

Thanks for your reply. There are more conditions in the other cells than in
A1, but I can fix that. I just needed to know how to capture that first set
of conditions, since all of the conditional tests give the same color
scheme.This will do just fine.
 
A

Alan

Thanks for your reply. There are more conditions in the other cells than in
A1, but I can fix that. I just needed to know how to capture that first set
of conditions, since all of the conditional tests give the same color
scheme.This will do just fine

Just in case, you appear to need only change one character ...

Sub CopyColors


Dim FCondition as FormatCondition
Dim i as integer


i=1
For Each FCondition in Activecell.FormatConditions
With ActiveCell.FormatConditions(i).Font
.ColorIndex=Range("A1").FormatConditions(1).Font.ColorIndex
' above FormatConditions(i) has become FormatConditions(1)
' now all conditional formats in the selected cell will change to
match
' the first (or only) conditional color in cell A1
End With
i=i+1
Next


end sub
 

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