#1   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 31
Default Count function

I am trying to count the number of occurences that the word "equity" appears
in a range. The range is always going to be column U. However, U3 will
always be the first cell in the range but the last cell varies depending on
the data. So I am running a loop to get to the bottom of the range. Once
there I want to run a count command that will count the number of times
"equity" appears in the column.

I am getting an error on my "countif" part that says sub or function not
defined. Not sure if I am even using this correctly. Any ideas?


Sub counting()

Range("U3").Activate

Do Until ActiveCell = ""
ActiveCell.Offset(1, 0).Select

Loop

ActiveCell.Value = CountIf("U3, ActiveCell.Offset(-1, 0)", "Equity")

End Sub


Thanks

Cluckers
  #2   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 2,722
Default Count function

CountIf is a Worksheetfunction, and you need to define the range properly.

Sub counting()

Range("U3").Activate
Do Until ActiveCell = ""
ActiveCell.Offset(1, 0).Select
Loop
ActiveCell.Value = WorksheetFunction.CountIf _
(Range("U3", ActiveCell.Offset(-1, 0)), "Equity")
End Sub


Alternatively, another way to do this, since you are looping anyway:

Sub counting()
xCount = 0
Range("U3").Activate
Do Until ActiveCell = ""
If ActiveCell.Value = "Equity" then
xCount = xCount +1
ActiveCell.Offset(1, 0).Select
Loop
ActiveCell.Value = xCount
End Sub

--
Best Regards,

Luke M
*Remember to click "yes" if this post helped you!*


"cluckers" wrote:

I am trying to count the number of occurences that the word "equity" appears
in a range. The range is always going to be column U. However, U3 will
always be the first cell in the range but the last cell varies depending on
the data. So I am running a loop to get to the bottom of the range. Once
there I want to run a count command that will count the number of times
"equity" appears in the column.

I am getting an error on my "countif" part that says sub or function not
defined. Not sure if I am even using this correctly. Any ideas?


Sub counting()

Range("U3").Activate

Do Until ActiveCell = ""
ActiveCell.Offset(1, 0).Select

Loop

ActiveCell.Value = CountIf("U3, ActiveCell.Offset(-1, 0)", "Equity")

End Sub


Thanks

Cluckers

  #3   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 8,520
Default Count function

You dont need to loop...Try the below...

Sub counting()
Dim lngRow As Long
lngRow = Cells(Rows.Count, "U").End(xlUp).Row
Range("U" & lngRow + 1) = "=COUNTIF(U3:U" & lngRow & ",""Equity"")"
End Sub

If this post helps click Yes
---------------
Jacob Skaria


"cluckers" wrote:

I am trying to count the number of occurences that the word "equity" appears
in a range. The range is always going to be column U. However, U3 will
always be the first cell in the range but the last cell varies depending on
the data. So I am running a loop to get to the bottom of the range. Once
there I want to run a count command that will count the number of times
"equity" appears in the column.

I am getting an error on my "countif" part that says sub or function not
defined. Not sure if I am even using this correctly. Any ideas?


Sub counting()

Range("U3").Activate

Do Until ActiveCell = ""
ActiveCell.Offset(1, 0).Select

Loop

ActiveCell.Value = CountIf("U3, ActiveCell.Offset(-1, 0)", "Equity")

End Sub


Thanks

Cluckers

  #4   Report Post  
Posted to microsoft.public.excel.misc
Ben Ben is offline
external usenet poster
 
Posts: 509
Default Count function

Try this:

Countif "Mark Roll" = Subset(0.0);
Then "Squirrel Master" = "Get back to work"

"cluckers" wrote:

I am trying to count the number of occurences that the word "equity" appears
in a range. The range is always going to be column U. However, U3 will
always be the first cell in the range but the last cell varies depending on
the data. So I am running a loop to get to the bottom of the range. Once
there I want to run a count command that will count the number of times
"equity" appears in the column.

I am getting an error on my "countif" part that says sub or function not
defined. Not sure if I am even using this correctly. Any ideas?


Sub counting()

Range("U3").Activate

Do Until ActiveCell = ""
ActiveCell.Offset(1, 0).Select

Loop

ActiveCell.Value = CountIf("U3, ActiveCell.Offset(-1, 0)", "Equity")

End Sub


Thanks

Cluckers

  #5   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 3,942
Default Count function

hi
if all you are trying to do is put the value of the count in last cell,
this might be a better way
Sub countit()
Dim c As Long
c = 0
Range("U3").Activate
Do Until ActiveCell = ""
ActiveCell.Offset(1, 0).Select
If ActiveCell.Value = "Equity" Then
c = c + 1
End If
Loop
ActiveCell.Value = c
end sub

regards
FSt1

"cluckers" wrote:

I am trying to count the number of occurences that the word "equity" appears
in a range. The range is always going to be column U. However, U3 will
always be the first cell in the range but the last cell varies depending on
the data. So I am running a loop to get to the bottom of the range. Once
there I want to run a count command that will count the number of times
"equity" appears in the column.

I am getting an error on my "countif" part that says sub or function not
defined. Not sure if I am even using this correctly. Any ideas?


Sub counting()

Range("U3").Activate

Do Until ActiveCell = ""
ActiveCell.Offset(1, 0).Select

Loop

ActiveCell.Value = CountIf("U3, ActiveCell.Offset(-1, 0)", "Equity")

End Sub


Thanks

Cluckers



  #6   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 31
Default Count function

that worked great.

do you know what is wrong with this. I am trying to sum the four cells
above my activecell

ActiveCell.Value = "Total" & " - " & Application.WorksheetFunction.Sum _
Range(Acivecell.Offset(-4, 0), ActiveCell.Offset(-1, 0)))

I am getting a syntax error


"Luke M" wrote:

CountIf is a Worksheetfunction, and you need to define the range properly.

Sub counting()

Range("U3").Activate
Do Until ActiveCell = ""
ActiveCell.Offset(1, 0).Select
Loop
ActiveCell.Value = WorksheetFunction.CountIf _
(Range("U3", ActiveCell.Offset(-1, 0)), "Equity")
End Sub


Alternatively, another way to do this, since you are looping anyway:

Sub counting()
xCount = 0
Range("U3").Activate
Do Until ActiveCell = ""
If ActiveCell.Value = "Equity" then
xCount = xCount +1
ActiveCell.Offset(1, 0).Select
Loop
ActiveCell.Value = xCount
End Sub

--
Best Regards,

Luke M
*Remember to click "yes" if this post helped you!*


"cluckers" wrote:

I am trying to count the number of occurences that the word "equity" appears
in a range. The range is always going to be column U. However, U3 will
always be the first cell in the range but the last cell varies depending on
the data. So I am running a loop to get to the bottom of the range. Once
there I want to run a count command that will count the number of times
"equity" appears in the column.

I am getting an error on my "countif" part that says sub or function not
defined. Not sure if I am even using this correctly. Any ideas?


Sub counting()

Range("U3").Activate

Do Until ActiveCell = ""
ActiveCell.Offset(1, 0).Select

Loop

ActiveCell.Value = CountIf("U3, ActiveCell.Offset(-1, 0)", "Equity")

End Sub


Thanks

Cluckers

  #7   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 2,722
Default Count function

Typo on the 2nd line. Change "Acivecell" to "ActiveCell".
--
Best Regards,

Luke M
*Remember to click "yes" if this post helped you!*


"cluckers" wrote:

that worked great.

do you know what is wrong with this. I am trying to sum the four cells
above my activecell

ActiveCell.Value = "Total" & " - " & Application.WorksheetFunction.Sum _
Range(Acivecell.Offset(-4, 0), ActiveCell.Offset(-1, 0)))

I am getting a syntax error


"Luke M" wrote:

CountIf is a Worksheetfunction, and you need to define the range properly.

Sub counting()

Range("U3").Activate
Do Until ActiveCell = ""
ActiveCell.Offset(1, 0).Select
Loop
ActiveCell.Value = WorksheetFunction.CountIf _
(Range("U3", ActiveCell.Offset(-1, 0)), "Equity")
End Sub


Alternatively, another way to do this, since you are looping anyway:

Sub counting()
xCount = 0
Range("U3").Activate
Do Until ActiveCell = ""
If ActiveCell.Value = "Equity" then
xCount = xCount +1
ActiveCell.Offset(1, 0).Select
Loop
ActiveCell.Value = xCount
End Sub

--
Best Regards,

Luke M
*Remember to click "yes" if this post helped you!*


"cluckers" wrote:

I am trying to count the number of occurences that the word "equity" appears
in a range. The range is always going to be column U. However, U3 will
always be the first cell in the range but the last cell varies depending on
the data. So I am running a loop to get to the bottom of the range. Once
there I want to run a count command that will count the number of times
"equity" appears in the column.

I am getting an error on my "countif" part that says sub or function not
defined. Not sure if I am even using this correctly. Any ideas?


Sub counting()

Range("U3").Activate

Do Until ActiveCell = ""
ActiveCell.Offset(1, 0).Select

Loop

ActiveCell.Value = CountIf("U3, ActiveCell.Offset(-1, 0)", "Equity")

End Sub


Thanks

Cluckers

  #8   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 22,906
Default Count function

Couple of typos in your posted code

Try this version.................

ActiveCell.Value = "Total" & " - " & Application.WorksheetFunction.Sum _
(Range(ActiveCell.Offset(-4, 0), ActiveCell.Offset(-1, 0)))


Gord Dibben MS Excel MVP

On Mon, 17 Aug 2009 11:43:01 -0700, cluckers
wrote:

that worked great.

do you know what is wrong with this. I am trying to sum the four cells
above my activecell

ActiveCell.Value = "Total" & " - " & Application.WorksheetFunction.Sum _
Range(Acivecell.Offset(-4, 0), ActiveCell.Offset(-1, 0)))

I am getting a syntax error


"Luke M" wrote:

CountIf is a Worksheetfunction, and you need to define the range properly.

Sub counting()

Range("U3").Activate
Do Until ActiveCell = ""
ActiveCell.Offset(1, 0).Select
Loop
ActiveCell.Value = WorksheetFunction.CountIf _
(Range("U3", ActiveCell.Offset(-1, 0)), "Equity")
End Sub


Alternatively, another way to do this, since you are looping anyway:

Sub counting()
xCount = 0
Range("U3").Activate
Do Until ActiveCell = ""
If ActiveCell.Value = "Equity" then
xCount = xCount +1
ActiveCell.Offset(1, 0).Select
Loop
ActiveCell.Value = xCount
End Sub

--
Best Regards,

Luke M
*Remember to click "yes" if this post helped you!*


"cluckers" wrote:

I am trying to count the number of occurences that the word "equity" appears
in a range. The range is always going to be column U. However, U3 will
always be the first cell in the range but the last cell varies depending on
the data. So I am running a loop to get to the bottom of the range. Once
there I want to run a count command that will count the number of times
"equity" appears in the column.

I am getting an error on my "countif" part that says sub or function not
defined. Not sure if I am even using this correctly. Any ideas?


Sub counting()

Range("U3").Activate

Do Until ActiveCell = ""
ActiveCell.Offset(1, 0).Select

Loop

ActiveCell.Value = CountIf("U3, ActiveCell.Offset(-1, 0)", "Equity")

End Sub


Thanks

Cluckers


  #9   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 31
Default Count function

Thanks

dah

"Luke M" wrote:

Typo on the 2nd line. Change "Acivecell" to "ActiveCell".
--
Best Regards,

Luke M
*Remember to click "yes" if this post helped you!*


"cluckers" wrote:

that worked great.

do you know what is wrong with this. I am trying to sum the four cells
above my activecell

ActiveCell.Value = "Total" & " - " & Application.WorksheetFunction.Sum _
Range(Acivecell.Offset(-4, 0), ActiveCell.Offset(-1, 0)))

I am getting a syntax error


"Luke M" wrote:

CountIf is a Worksheetfunction, and you need to define the range properly.

Sub counting()

Range("U3").Activate
Do Until ActiveCell = ""
ActiveCell.Offset(1, 0).Select
Loop
ActiveCell.Value = WorksheetFunction.CountIf _
(Range("U3", ActiveCell.Offset(-1, 0)), "Equity")
End Sub


Alternatively, another way to do this, since you are looping anyway:

Sub counting()
xCount = 0
Range("U3").Activate
Do Until ActiveCell = ""
If ActiveCell.Value = "Equity" then
xCount = xCount +1
ActiveCell.Offset(1, 0).Select
Loop
ActiveCell.Value = xCount
End Sub

--
Best Regards,

Luke M
*Remember to click "yes" if this post helped you!*


"cluckers" wrote:

I am trying to count the number of occurences that the word "equity" appears
in a range. The range is always going to be column U. However, U3 will
always be the first cell in the range but the last cell varies depending on
the data. So I am running a loop to get to the bottom of the range. Once
there I want to run a count command that will count the number of times
"equity" appears in the column.

I am getting an error on my "countif" part that says sub or function not
defined. Not sure if I am even using this correctly. Any ideas?


Sub counting()

Range("U3").Activate

Do Until ActiveCell = ""
ActiveCell.Offset(1, 0).Select

Loop

ActiveCell.Value = CountIf("U3, ActiveCell.Offset(-1, 0)", "Equity")

End Sub


Thanks

Cluckers

Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Count Function Mickey Excel Worksheet Functions 5 November 12th 08 11:55 PM
COUNT Function SiH23 Excel Discussion (Misc queries) 3 November 2nd 08 09:28 PM
Count/if/and function? tonyalt3 Excel Worksheet Functions 6 March 25th 08 09:26 PM
Count If Function benny Excel Worksheet Functions 10 October 4th 07 02:45 PM
i need help with the "count" function kippercat Excel Worksheet Functions 1 March 9th 05 09:58 AM


All times are GMT +1. The time now is 08:22 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"