Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.worksheet.functions
external usenet poster
 
Posts: 13
Default using =COUNTIF() in a variable range on a different worksheet?

Help please.

I just got an nice answer on how to use the ".Formula()" function
programmatically but I forgot one detail: the range has to be
variable:

'ActiveWorkbook.Sheets("WSB").Cells(1, 2).Formula ="=COUNTIF('WSA'!
D2:D36000,""<N/A"")"

So, imagine that the range "D2:D36000" is dynamic. I've been trying
to substitute the value of "D36000" using "&d_end" but no success.
Something is telling me I should use a "range" type variable but I'm
too newbie I think.

Thanks.


  #2   Report Post  
Posted to microsoft.public.excel.worksheet.functions
external usenet poster
 
Posts: 10,124
Default using =COUNTIF() in a variable range on a different worksheet?

try something like:

lastrow=sheets("wsa").cells(rows.count,"d").end(xl up).row
ActiveWorkbook.Sheets("WSB").Cells(1, 2).Formula ="=COUNTIF('WSA'!
D2:D" & lastrow & ",""<N/A"")"




--
Don Guillett
Microsoft MVP Excel
SalesAid Software

"circuit_breaker" wrote in message
...
Help please.

I just got an nice answer on how to use the ".Formula()" function
programmatically but I forgot one detail: the range has to be
variable:

'ActiveWorkbook.Sheets("WSB").Cells(1, 2).Formula ="=COUNTIF('WSA'!
D2:D36000,""<N/A"")"

So, imagine that the range "D2:D36000" is dynamic. I've been trying
to substitute the value of "D36000" using "&d_end" but no success.
Something is telling me I should use a "range" type variable but I'm
too newbie I think.

Thanks.



  #3   Report Post  
Posted to microsoft.public.excel.worksheet.functions
external usenet poster
 
Posts: 13
Default using =COUNTIF() in a variable range on a different worksheet?

On Jul 6, 11:11*am, "Don Guillett" wrote:
try something like:

lastrow=sheets("wsa").cells(rows.count,"d").end(xl up).row
ActiveWorkbook.Sheets("WSB").Cells(1, 2).Formula ="=COUNTIF('WSA'!

D2:D" & lastrow & ",""<N/A"")"


--
Don Guillett
Microsoft MVP Excel
SalesAid Software
"circuit_breaker" wrote in message

...



Help please.


I just got an nice answer on how to use the ".Formula()" function
programmatically but I forgot one detail: the range has to be
variable:


'ActiveWorkbook.Sheets("WSB").Cells(1, 2).Formula ="=COUNTIF('WSA'!
D2:D36000,""<N/A"")"


So, imagine that the range "D2:D36000" is dynamic. *I've been trying
to substitute the value of "D36000" using "&d_end" but no success.
Something is telling me I should use a "range" type variable but I'm
too newbie I think.


Thanks.- Hide quoted text -


- Show quoted text -


Brilliant. It worked. However, I changed your formula for:

LastCellInColumn = ActiveWorkbook.Sheets("WSA").UsedRange.Rows.Count

in order to pick the very last cell used in that column.

Thanks again.

  #4   Report Post  
Posted to microsoft.public.excel.worksheet.functions
external usenet poster
 
Posts: 10,124
Default using =COUNTIF() in a variable range on a different worksheet?

Sending you a workbook showing that if you want to get the last row in col
D.

Sub usedrngelastrow()
MsgBox ActiveSheet.UsedRange.Rows.Count
MsgBox "Using xlup col d is row " & Cells(Rows.Count, "d").End(xlUp).Row
End Sub


--
Don Guillett
Microsoft MVP Excel
SalesAid Software

"circuit_breaker" wrote in message
...
On Jul 6, 11:11 am, "Don Guillett" wrote:
try something like:

lastrow=sheets("wsa").cells(rows.count,"d").end(xl up).row
ActiveWorkbook.Sheets("WSB").Cells(1, 2).Formula ="=COUNTIF('WSA'!

D2:D" & lastrow & ",""<N/A"")"


--
Don Guillett
Microsoft MVP Excel
SalesAid Software
"circuit_breaker"
wrote in message

...



Help please.


I just got an nice answer on how to use the ".Formula()" function
programmatically but I forgot one detail: the range has to be
variable:


'ActiveWorkbook.Sheets("WSB").Cells(1, 2).Formula ="=COUNTIF('WSA'!
D2:D36000,""<N/A"")"


So, imagine that the range "D2:D36000" is dynamic. I've been trying
to substitute the value of "D36000" using "&d_end" but no success.
Something is telling me I should use a "range" type variable but I'm
too newbie I think.


Thanks.- Hide quoted text -


- Show quoted text -


Brilliant. It worked. However, I changed your formula for:

LastCellInColumn = ActiveWorkbook.Sheets("WSA").UsedRange.Rows.Count

in order to pick the very last cell used in that column.

Thanks again.

  #5   Report Post  
Posted to microsoft.public.excel.worksheet.functions
external usenet poster
 
Posts: 10,124
Default using =COUNTIF() in a variable range on a different worksheet?

To find the very last row of the sheet

lastrow = Cells.Find(What:="*", After:=[A1], _
SearchOrder:=xlByRows, _
SearchDirection:=xlPrevious).Row

MsgBox "Real last row of spreadsheet is " & lastrow

--
Don Guillett
Microsoft MVP Excel
SalesAid Software

"Don Guillett" wrote in message
...
Sending you a workbook showing that if you want to get the last row in col
D.

Sub usedrngelastrow()
MsgBox ActiveSheet.UsedRange.Rows.Count
MsgBox "Using xlup col d is row " & Cells(Rows.Count, "d").End(xlUp).Row
End Sub


--
Don Guillett
Microsoft MVP Excel
SalesAid Software

"circuit_breaker" wrote in message
...
On Jul 6, 11:11 am, "Don Guillett" wrote:
try something like:

lastrow=sheets("wsa").cells(rows.count,"d").end(xl up).row
ActiveWorkbook.Sheets("WSB").Cells(1, 2).Formula ="=COUNTIF('WSA'!

D2:D" & lastrow & ",""<N/A"")"


--
Don Guillett
Microsoft MVP Excel
SalesAid Software
"circuit_breaker"
wrote in message

...



Help please.


I just got an nice answer on how to use the ".Formula()" function
programmatically but I forgot one detail: the range has to be
variable:


'ActiveWorkbook.Sheets("WSB").Cells(1, 2).Formula ="=COUNTIF('WSA'!
D2:D36000,""<N/A"")"


So, imagine that the range "D2:D36000" is dynamic. I've been trying
to substitute the value of "D36000" using "&d_end" but no success.
Something is telling me I should use a "range" type variable but I'm
too newbie I think.


Thanks.- Hide quoted text -


- Show quoted text -


Brilliant. It worked. However, I changed your formula for:

LastCellInColumn = ActiveWorkbook.Sheets("WSA").UsedRange.Rows.Count

in order to pick the very last cell used in that column.

Thanks again.


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
Copying a variable range of data from one worksheet to another. AllyB Excel Discussion (Misc queries) 3 March 2nd 09 11:37 PM
Variable named range in worksheet function Barb Reinhardt Excel Worksheet Functions 6 July 26th 08 03:39 AM
Using variable sized range in CountIf() [email protected][_2_] Excel Discussion (Misc queries) 1 October 24th 07 11:15 AM
Excel Named Formula Weakly Interacts with a Variable Range on the Worksheet - Re-Visit [email protected] Excel Discussion (Misc queries) 5 September 6th 07 06:42 PM
variable range countif JK Excel Worksheet Functions 3 November 3rd 04 07:50 AM


All times are GMT +1. The time now is 07:59 PM.

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"