Filter Bold Cells

There is no straightforward way to filter the bold cells in VBA. Does that mean that we cannot filter bold cells? I’m not saying that. Almost everything that we can do manually in Excel. VBA language allows us to perform. So, let's look at how we can filter bold cells in VBA.

We have an excel file with some sales data. There are several bold rows in this data. We need to write VBA code to filter those rows.

We are aware that we cannot directly filter a bold row. What then shall we do? We will add a helper column next to the last column. Whether a cell's font is bold or not will be determined in that column by using Font.Bold property of Range object.


When a cell contains the bold value, the Font.Bold Property will return true; otherwise, it will return false. In that helper column, we can write down these True and False values.

							
  Sub FilterBoldCells()
	Dim sh As Worksheet
	Dim index As Integer
   
	Set sh = ThisWorkbook.Worksheets("SalesData")
	  
	For index = 2 To sh.Cells(Rows.Count, 1).End(xlUp).Row
		 sh.Range("H" & index).Value = sh.Range("A" & index).Font.Bold
	Next index
  End Sub
							

Now, where the font text is bold, we have true; elsewhere, we have false. We can easily filter true values from the helper column if we want to filter bold cells. And after filtering the values, we can hide the helper column.

							
  Sub FilterBoldCells()
    Dim sh As Worksheet
    Dim index As Integer
   
	Set sh = ThisWorkbook.Worksheets("SalesData")
	  
	For index = 2 To sh.Cells(Rows.Count, 1).End(xlUp).Row
		 sh.Range("H" & index).Value = sh.Range("A" & index).Font.Bold
	Next index
	  
	sh.Range("A1").AutoFilter Field:=8, Criteria1:="True"
	  
	sh.Range("H1").EntireColumn.Hidden = True
  End Sub
							

Stay connect with us.