Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Highlight a column when first row is equal to "1"

Status
Not open for further replies.

arbo80

Programmer
Jan 5, 2006
53
0
0
US
Hi all,

I would like to create a macro that highlights multiple columns in Excel when the first row of the column is equal to "1". I was able to find the solution for one column but I would like to do the same for 50 or more columns and I don't want to copy and paste my code. Is there any easier way? Here is my current code for the first column but I need one for 50:

Sub colorColumn()
If (Range("A1").Value = "1") Then
Range("A2:A50").Select
With Selection.Interior
.ColorIndex = 6
.Pattern = xlSolid
End With
Else
Range("A2:A50").Select
Selection.Interior.ColorIndex = xlNone
End If
End Sub

Thanks,

Armel
 
No VBA required.

See Format > Conditional Formatting. Check out Excel's help file entry for it.

thread68-1484508 might be of some help to you.

[tt]_____
[blue]-John[/blue][/tt]
[tab][red]The plural of anecdote is not data[/red]

Help us help you. Please read FAQ 181-2886 before posting.
 



Hi,

Don't need VBA to do this. Check out Format > Conditional Formatting

Select ALL the cells you want to format before you Format > Conditional Formatting.

Enter the formula in CF as if you are in the ActiveCell. Will be applied to the entire range.


Skip,
[sub]
[glasses]Just traded in my old subtlety...
for a NUANCE![tongue][/sub]
 
Thanks guys for your help! but how do I make sure that it highlights the entire column instead of just the cell?
 




"Select ALL the cells you want to format before you Format > Conditional Formatting."

Make sure that the reference is ABSOLUTE to Row 1 and relative to the column. ie =A$1=1 if your activecell is in column A.

Skip,
[sub]
[glasses]Just traded in my old subtlety...
for a NUANCE![tongue][/sub]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top