Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,092
Default Syntax for WorksheetFunction

Sub CntIf()
Dim Ldb, rwct, counter
Dim myrng As Range

Sheets("Node Data").Activate
If Range("B2").Value = "" Then
Cells(1, counter + 2).Value = "Total Leaks per " & Ldb
Set myrng = Sheets(Ldb).Range("$B$2:$B$" & rwct)

Range(Cells(2, counter + 2), Cells(85, counter + 2)) =
Application.WorksheetFunction.CountIf(myrng, "$A$2:$A$85") 'This does not
work
Range(Cells(2, counter + 3), Cells(85, counter + 3)).Formula =
"=COUNTIF(LAFQ403!$B$2:$B$568,$A$2:$A$85)" 'This works

End If
End Sub

How do I get the variables to work in the WorksheetFunction?
The variable values at these lines a
Ldb = "LAFQ403"
rwct = 568
counter = 0

TIA
Mike


  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default Syntax for WorksheetFunction

the second argument of Countif should be a single value. When entered in
the worksheet, you are using implicit intersection, so it is only getting
one value. If you moved the location of your formulas to start in row 86 to
168, it wouldn't work Your easiest fix would probably be just to loop

set myrng = Range("LAFQ403!$B$2:$B$568")
for rw = 2 to 85
Cells(rw, counter + 2) =
Application.WorksheetFunction.CountIf(myrng, Cells(rw,1))
Next

--
Regards,
Tom Ogilvy

"Mike Fogleman" wrote in message
...
Sub CntIf()
Dim Ldb, rwct, counter
Dim myrng As Range

Sheets("Node Data").Activate
If Range("B2").Value = "" Then
Cells(1, counter + 2).Value = "Total Leaks per " & Ldb
Set myrng = Sheets(Ldb).Range("$B$2:$B$" & rwct)

Range(Cells(2, counter + 2), Cells(85, counter + 2)) =
Application.WorksheetFunction.CountIf(myrng, "$A$2:$A$85") 'This does not
work
Range(Cells(2, counter + 3), Cells(85, counter + 3)).Formula =
"=COUNTIF(LAFQ403!$B$2:$B$568,$A$2:$A$85)" 'This works

End If
End Sub

How do I get the variables to work in the WorksheetFunction?
The variable values at these lines a
Ldb = "LAFQ403"
rwct = 568
counter = 0

TIA
Mike




  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3,885
Default Syntax for WorksheetFunction

Hi Mike
the problem is that the second parameter of COUNTIF should be only a
single value. e.g.
Application.WorksheetFunction.CountIf(myrng, "$A$2")

As I'm not so sure what you want to achieve you may have to loop
through this second range to get all your counts?


--
Regards
Frank Kabel
Frankfurt, Germany

Mike Fogleman wrote:
Sub CntIf()
Dim Ldb, rwct, counter
Dim myrng As Range

Sheets("Node Data").Activate
If Range("B2").Value = "" Then
Cells(1, counter + 2).Value = "Total Leaks per " & Ldb
Set myrng = Sheets(Ldb).Range("$B$2:$B$" & rwct)

Range(Cells(2, counter + 2), Cells(85, counter + 2)) =
Application.WorksheetFunction.CountIf(myrng, "$A$2:$A$85") 'This
does not work
Range(Cells(2, counter + 3), Cells(85, counter + 3)).Formula =
"=COUNTIF(LAFQ403!$B$2:$B$568,$A$2:$A$85)" 'This works

End If
End Sub

How do I get the variables to work in the WorksheetFunction?
The variable values at these lines a
Ldb = "LAFQ403"
rwct = 568
counter = 0

TIA
Mike


  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 13
Default Syntax for WorksheetFunction

Thanks Tom & Frank. I wasn't aware that I was violating an implicit
intersection by using a criteria range than 1 cell. The loop that Tom used
works fine in this instance.
Mike Fogleman wrote in message
...
Sub CntIf()
Dim Ldb, rwct, counter
Dim myrng As Range

Sheets("Node Data").Activate
If Range("B2").Value = "" Then
Cells(1, counter + 2).Value = "Total Leaks per " & Ldb
Set myrng = Sheets(Ldb).Range("$B$2:$B$" & rwct)

Range(Cells(2, counter + 2), Cells(85, counter + 2)) =
Application.WorksheetFunction.CountIf(myrng, "$A$2:$A$85") 'This does not
work
Range(Cells(2, counter + 3), Cells(85, counter + 3)).Formula =
"=COUNTIF(LAFQ403!$B$2:$B$568,$A$2:$A$85)" 'This works

End If
End Sub

How do I get the variables to work in the WorksheetFunction?
The variable values at these lines a
Ldb = "LAFQ403"
rwct = 568
counter = 0

TIA
Mike




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
WorksheetFunction help Ayo Excel Discussion (Misc queries) 2 July 20th 08 10:48 PM
WorksheetFunction with VBA Ghislain Marcotte Excel Discussion (Misc queries) 2 February 13th 05 07:08 AM
WorkSheetFunction.CountIf & WorkSheetFunction.SumIf with 2 conditions? Etien[_2_] Excel Programming 3 January 13th 04 04:07 PM
WorksheetFunction Mike Fogleman Excel Programming 2 January 1st 04 11:17 PM
worksheetfunction devnext Excel Programming 1 October 29th 03 12:48 PM


All times are GMT +1. The time now is 08:10 PM.

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

About Us

"It's about Microsoft Excel"