Macro to clear all Bold Items in Col B

howard

Well-known Member
Joined
Jun 26, 2006
Messages
6,563
Office Version
  1. 2021
Platform
  1. Windows
I have tried to write code to clear all bold items in col B on sheet "Data Import"


However when running my code no items are being cleared


Code:
 Sub Clear_BoldItems()
With Sheets("Data Import")
Dim LR As Long
    LR = .Cells(.Rows.Count, "B").End(xlUp).Row
        If .Range("B1:B" & LR).Font.Bold = True Then
        .Range("B1:B" & LR).ClearContents
          End If
        End With
       
       
End Sub

It would be appreciated if someone could kindly amend my code.
 

Excel Facts

VLOOKUP to Left?
Use =VLOOKUP(A2,CHOOSE({1,2},$Z$1:$Z$99,$Y$1:$Y$99),2,False) to lookup Y values to left of Z values.
Hi
Try
VBA Code:
Sub Clear_BoldItems()
    With Sheets("Data Import")
        Dim LR As Long
        LR = .Cells(.Rows.Count, "B").End(xlUp).Row
        For i = 1 To LR
            If .Range("B" & i).Font.Bold = True Then
                .Range("B" & i).ClearContents
            End If
        Next
    End With
End Sub
 
Upvote 0
You can also do this without using any loops at all...
VBA Code:
Sub Clear_BoldItems()
  With Application
    .FindFormat.Clear
    .FindFormat.Font.Bold = True
    Sheets("Data Import").Columns("B").Replace "", "", xlWhole, , , , True, False
    .FindFormat.Clear
  End With
End Sub
 
Upvote 0
Thanks Mohadin & Rick for your help


However when running the code the bold items are not being cleared


See my Sample Data below

Kindly test & amend code so that the bold items are cleared (The data has been imported in this format)


 
Upvote 0
In Rick's code just change this line
VBA Code:
.FindFormat.Font.Name = "Arial Bold"
instead of this line
VBA Code:
.FindFormat.Font.Bold = True
 
Upvote 0
Solution
I am not sure why, but even though you show the file as an xlsm type file, I cannot download it to my computer... it only opens in the online version of Excel where nothing shows as bold. Also, in reference to YasserKhalil's post, I only see all the cells as having Arial font, not Arial Bold, but if that is how you made the bolded the text, his proposed changed to my code should work for you.
 
Upvote 0
Thanks YasserKhahill for your input. It now works perfectly

Ricky, not sure why file cannot be downloaded, but glad problem has been resolved
 
Upvote 0

Forum statistics

Threads
1,215,029
Messages
6,122,755
Members
449,094
Latest member
dsharae57

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