RE: "Counter" in macro



Hi,

You don't need a macro this will do it

=COUNTIF(A1:D200,"Boo")

But if you have a particular reson for wanting a macro then use this

Sub marine()
Dim Myrange As Range
Set Myrange = Range("A1:D200")
For Each c In Myrange
If UCase(Trim(c.Value)) = "BOO" Then
Count = Count + 1
End If
Next
MsgBox Count
End Sub

Mike

"bobkap" wrote:

Can anyone help me with this please?
I want to run a macro that loops through many rows of data and counts each
time a certain condition is met. For example, lets say I have 200 rows of
data that's 4 columns wide. I want to know how many times the word "boo" has
occurred in any of these 800 cells.

Thanks!
.



Relevant Pages

  • Re: How do I make a unique entry
    ... The macro is actually shorter ) ... Sub concat() ... >> Dim myrange As Range ...
    (microsoft.public.excel.newusers)
  • RE: excel macro help... please
    ... "Mike H" wrote: ... Sub sortem() ... Dim MyRange As Range ... I want a macro that checks if the date in A1 matches B1 ...
    (microsoft.public.excel.programming)
  • RE: excel macro help... please
    ... right click your sheet tab, view code and paste this in and run it. ... Sub sortem() ... Dim MyRange As Range ... I want a macro that checks if the date in A1 matches B1 ...
    (microsoft.public.excel.programming)
  • RE: IF statements in Macros
    ... Dim MyRange As Range ... ElseIf Left= "GTS" Then ... End Sub ... statements within the same macro or do i need to create seperate modules? ...
    (microsoft.public.excel.programming)
  • Re: Sequential Numbers
    ... Sub Marine() ... ' Pete Ashurst, 08/01/2009 ... S6 will contain 201 at the end of the macro. ...
    (microsoft.public.excel.misc)

Loading