I have range and i want to highlight my range of cells based value i enter in cell Range("C5"). If i enter 5 in cell "C5" then 5 cells in my range needs to be changed to yellow color.
Dim MY_RANGE As Range
Dim VALUE1 As Integer
Dim CEL As String
Set MY_RANGE = Range("H8,J8,L8,N8,H10,H10,J10,L10,N10,H12,J12,L12,N12,H14,J14,L14,N14,H16,J16,L16,N16,N16")
VALUE1 = Range("C2")
For Each CEL In MY_RANGE.Cells
If CEL.Value = VALUE1 Then
With CEL
.Italic = False
.Bold = True
.Color = 255
.TintAndShade = 0
End With
End If
Next CEL
Can someone help pls..
you can use
Areas()
property ofRange()
object:Note: in your
MY_RANGE
range there were two "H10" occurrencesYou need to introduce a counter and to count:
The idea is that every time the code loops the counter is increased with
1
, hencecnt = cnt + 1
. If it loops N exactlyRange("C2")
times, it exits.