Thread: Count function
View Single Post
  #9   Report Post  
Posted to microsoft.public.excel.misc
cluckers cluckers is offline
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