Reputation: 47
How do I bold all cells that contain 1470?
I tried looping
Sub bold()
Dim rng As Range, cell As Range
Set rng = Range("j259:j291")
For Each cell In rng
If rng.Cells = "1470" Then
rng.Cells.Font.bold = True
End If
Next cell
End Sub
I got the error
"Type mismatch"
Upvotes: 0
Views: 2096
Reputation: 75840
Initial question
"Im looking for fastest way to bold all cell that contains value = "1470" by using vba"
This might be fast if you want to go with VBA instead of conditional formatting:
Sub bold()
Dim Rng As Range
Application.ReplaceFormat.Font.FontStyle = "Bold"
With ThisWorkbook.Sheets("Sheet1")
Set Rng = .Range("J259:J291")
Rng.Cells.Replace What:="1470", Lookat:=xlWhole, Replacement:="1470", SearchFormat:=False, ReplaceFormat:=True
End With
End Sub
Secundary question:
"addition to my question, if i want to make bold the entire row how can I possibly do it?"
In order to get your whole rows (or actually those cells you need) quickly bold you could use:
Sub bold()
Dim Rng As Range
With ThisWorkbook.Sheets("Sheet1")
Set Rng = .Range("A258:J291")
Rng.AutoFilter Field:=10, Criteria1:="1470"
Rng.Offset(1).Resize(Rng.Rows.Count - 1).SpecialCells(12).Font.bold = True
Rng.AutoFilter
End With
End Sub
If you want the whole row bold you could also swap the Rng.Offset...
line with:
Rows("259:291").SpecialCells(12).Font.bold = True
Adjust the variable Rng
to suit your needs.
Upvotes: 1
Reputation: 6654
Problems:
Advice:
Bold
, Cell
for variables or Module NameTry:
Sub bld()
Dim cel As Range
For Each cel In Range("J259:J291")
If cel.Value = "1470" Then
cel.Font.bold = True
End If
Next cel
End Sub
Upvotes: 1