Change Font/Color of Cells in a Particular Column

Michael151

Board Regular
Joined
Sep 20, 2010
Messages
247
Hello all,

Trying to write a macro that will change the font and color of specific text in a particular column.

I have a column with the header (row1) "deal_id" which can appear in column letter in the sheet. I'd like to use the header in row 1 as the identifier for this column.

Within that column, if the word "OPEN" is found in a cell, change the font to bold and the color to red of that cell.

Help is most appreciated - thanks!
 

Excel Facts

Does the VLOOKUP table have to be sorted?
No! when you are using an exact match, the VLOOKUP table can be in any order. Best-selling items at the top is actually the best.
Try:
Code:
Sub TryMe ()
Application.ScreenUpdating = False
Dim myHeader As String
Dim FoundColumn As Long, i As Long
If Len(Range("A1")) > 0 Then
  myHeader = Range("A1")
Else
  MsgBox "No header found, macro exiting"
  Exit Sub
End If
On Error GoTo Notfound
FoundColumn = Range(Cells(1, 2), Cells(1, Columns.Count)).Find(what:=myHeader, searchorder:=xlByColumns).Column
i = Cells(Rows.Count, FoundColumn).End(xlUp).Row
Do While i <> 1
    With Cells(i, FoundColumn)
        If .Value = "OPEN" Then
            .Font.Bold = True
            .Interior.ColorIndex = 3
        End If
    End With
    i = i - 1
Loop
Application.ScreenUpdating = True
Exit Sub
Notfound:
MsgBox "Header can't be found, macro exiting"
End Sub
 
Last edited:
Upvote 0
Thanks JackDanIce,

However, I get an error message saying "object variable not set" and highlights this line:

FoundColumn = Range(Cells(1, 2), Cells(1, Columns.Count)).Find(what:=myHeader, searchorder:=xlByColumns).Column
 
Upvote 0
Also, wondering where "deal_id" appears as something for the macro to find in the row 1 header - didn't see it included in the code.
 
Upvote 0
Your query wasn't clear so I assumed you were looking for whatever header was in cell A1 and then highlighting as required. The line you comment on works fine for me, but try this instead:
Code:
Sub TryMe ()
Application.ScreenUpdating = False
Dim FoundColumn As Long, i As Long
On Error GoTo Notfound
Range(Cells(1, 1), Cells(1, Columns.Count)).Find(what:="deal_id", searchorder:=xlByColumns).Select
FoundColumn = ActiveCell.Column
i = Cells(Rows.Count, FoundColumn).End(xlUp).Row
Do While i <> 1
    With Cells(i, FoundColumn)
        If .Value = "OPEN" Then
            .Font.Bold = True
            .Interior.ColorIndex = 3
        End If
    End With
    i = i - 1
Loop
Application.ScreenUpdating = True
Exit Sub
Notfound:
MsgBox "Header can't be found, macro exiting"
End Sub
F8 (step) through the code and you should see the column with deal_id selected first..
 
Upvote 0

Forum statistics

Threads
1,224,590
Messages
6,179,750
Members
452,940
Latest member
rootytrip

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