Hey guys I'm rather new to VBA and am encountering in quite an annoying issue, which relates to a loop I'm trying to execute. In essence I'm looking to conditional format every cell in a range which has a certain numeric value. The code seems to run fin if done manually line by line, by it produces a
'Run Time error 13 - Type mismatch'
when ran via the Run button. Precisely it breaks at the line containing the IF statement. Code below:
Sub Check_OOT()
Dim LastRow As Long
Dim Cell, CalcRange, FirstHeaderRow, LastColumn As Range
With ActiveSheet
Set LastColumn = .UsedRange.Find("Total", , xlValues, xlWhole)
Set FirstHeaderRow = .UsedRange.Find("Level 1", , xlValues, xlWhole)
LastRow = .Cells(Rows.Count, LastColumn.Column).End(xlUp).Row
Set CalcRange = .Range(.Cells(FirstHeaderRow.Row + 2, FirstHeaderRow.Column + 3), .Cells(LastRow, LastColumn.Column))
For Each Cell In CalcRange
If Cell.Value > 500 Or Cell.Value < -100 Then
Cell.Font.Bold = True
Cell.Interior.ColorIndex = 36
End If
Next Cell
End With
End Sub
Thanks very much for the help.
Aucun commentaire:
Enregistrer un commentaire