count resize range

R

roster_jon

Hey,

I need a VBA code that count the number of times "cf" occurs in the 14 cells
to the left of every cell, including the cell, in a range and change the
bottom border line to a thick red line if the count exceeds 4.

What I'm trying to do is point out if someone has been scheduled "cf" more
than 4 times in the past 14 days.

Is this possible at all?
 
J

JLGWhiz

Since you did not specify the columns and rows, I used columns A thru O,
with O being the one that holds the criteria to identify which rows to count
the "cf" in. You can alter the macro to suit your actual sheet content.

Sub dk()
Dim lr As Long, sh As Worksheet
Dim rng As Range, fRng As Range, c As Range
Set sh = ActiveSheet
lr = sh.Cells(Rows.Count, 15).End(xlUp).Row
Set rng = sh.Range("O2:O" & lr)
For Each c In rng
Set fRng = sh.Range("A" & c.Row & ":O" & c.Row)
If WorksheetFunction.CountIf(fRng, "cf") > 4 Then
With fRng.Borders(xlEdgeBottom)
.LineStyle = Solid
.Weight = xlThick
.ColorIndex = 3
End With
End If
Next
End Sub
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top