Bolding a Cell under certain conditions

  • Thread starter Thread starter DennyP
  • Start date Start date
D

DennyP

I am looking for a program/function that takes in a selected column,
and bolds any cell in that column where the cell above or the cell
below has the same value.

The worksheet is already sorted on the selected column.

Thanks for any pointers or suggestions for Excel 2007.
 
This code will scan Col.A and bold any cell that has same value above and
below it. You will have to change it to which ever Column you need.

Option Explicit

Sub BoldCells()

Dim i As Long

For i = 2 To Cells(Rows.Count, "A").End(xlUp).Row
If Cells(i - 1, "A").Value = Cells(i + 1, "A").Value Then
Cells(i, "A").Font.Bold = True
End If
Next i

End Sub

Hope this helps! If so, click "YES" below.
 
I am looking for a program/function that takes in a selected column,
and bolds any cell in that column where the cell above or the cell
below has the same value.

The worksheet is already sorted on the selected column.

Thanks for any pointers or suggestions for Excel 2007.

Use conditional formatting (on the Home tab)

To apply this to C2:C10000

"Use a formula to determine which cells to format"

=OR(OFFSET(C2,-1,0)=C2,OFFSET(C2,1,0)=C2)

Then, in the CF Rules Manager, ensure the format applies to

=$C$2:$C$10000

--ron
 
I made a slight change because I needed the bold to occur if the row
above or below was the same.

Sub BoldCells()
Dim i As Long
For i = 2 To Cells(Rows.Count, "A").End(xlUp).Row
If (Cells(i - 1, "A").Value = Cells(i, "A").Value) Or (Cells(i
+ 1, "A").Value = Cells(i, "A").Value) Then
Cells(i, "A").Font.Bold = True
End If
Next i
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

Back
Top