Count If Is Like

  • Thread starter Thread starter moglione1
  • Start date Start date
M

moglione1

Hi All,

I have a dilemma. I need to countif a range is like a value. I.e. I
need to count how many JUL appear in a certain range, the problem is
that the JUL may not always be in a cell on its own - it may have other
values such as JUL, AUG, SEP etc.

Is this possible to count. The code I currenty have is:

Sub countMth()
Dim i, ii As Long
Dim iii As Variant
Dim rR As Range
Dim C As Integer

C = 0

i = ActiveSheet.UsedRange.Cells.SpecialCells(xlCellTypeLastCell).Row
'find stuff
Cells(1, 1).Select
ii = Cells.Find(What:="Month Appeared", After:=ActiveCell,
LookIn:=xlValues, LookAt:= _
xlWhole, SearchOrder:=xlByRows, SearchDirection:=xlNext,
MatchCase:=True).Row
Cells(1, 1).Select
iii = Split(Cells.Find(What:="Month Appeared", After:=ActiveCell,
LookIn:=xlValues, LookAt:= _
xlWhole, SearchOrder:=xlByRows, SearchDirection:=xlNext,
MatchCase:=True).Address, "$")


For Each rR In Range(iii(1) & ii + 1 & ":" & iii(1) & i)

If myCheck = rR.Value Like "JUL" Then
C = C + 1
End If
Range("A5") = C
Next rR


End Sub
 
You can use wildcards in the COUNTIF worksheet function:

=COUNTIF(A1:A100,"*JUL*")

So you don't need VBA for this. However, if you need
to do it in a macro for some reason, you could use
Application.CountIf(myRange,"*JUL*")
 
You can use wildcards in the COUNTIF worksheet function:

=COUNTIF(A1:A100,"*JUL*")

So you don't need VBA for this. However, if you need
to do it in a macro for some reason, you could use
Application.CountIf(myRange,"*JUL*")
 

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

Back
Top