Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 37
Default countif syntax VBA

xl 2k
Win 2k

Trying to use VBA to enter a formula, must use RC
notiation so I can use variable number of rows, and then
will copy the formula using relative ranges and but still
mustuse a specific cell for the criteria.

sample snippet

Sub fixcount()
Dim counter As Integer
counter = 5
'what I want....
'Sheets("Test").Range("d3").FormulaR1C1 = "=COUNTIF(R[4]C:R
[" & counter & "]C,""" & value in a fixed cell & ")"""

'what I have --doesn't work run time 1004
Sheets("Test").Range("d3").FormulaR1C1 = "=COUNTIF(R[4]C:R
[" & counter & "]C,""" & "d1" & ")"""
End Sub

Is my problem a mix of RC and the "D1" notations?
TIA Dave
  #2   Report Post  
Posted to microsoft.public.excel.programming
rog rog is offline
external usenet poster
 
Posts: 39
Default countif syntax VBA

Just a few quotes in the wrong place Dave :

"=COUNTIF(R[4]C:R[" & counter & "]C,""" & "d1"")"

-----Original Message-----
xl 2k
Win 2k

Trying to use VBA to enter a formula, must use RC
notiation so I can use variable number of rows, and then
will copy the formula using relative ranges and but still
mustuse a specific cell for the criteria.

sample snippet

Sub fixcount()
Dim counter As Integer
counter = 5
'what I want....
'Sheets("Test").Range("d3").FormulaR1C1 = "=COUNTIF(R[4]

C:R
[" & counter & "]C,""" & value in a fixed cell & ")"""

'what I have --doesn't work run time 1004
Sheets("Test").Range("d3").FormulaR1C1 = "=COUNTIF(R[4]C:R
[" & counter & "]C,""" & "d1" & ")"""
End Sub

Is my problem a mix of RC and the "D1" notations?
TIA Dave
.

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default countif syntax VBA

You can't mix R1C1 notation and A1 notation in a single formula

ActiveCell.FormulaR1C1 = "=COUNTIF(R[4]C:R[" & counter & "]C,"""" &R1C4)"

all on one line worked for me.

--
Regards,
Tom Ogilvy



"Rog" wrote in message
...
Just a few quotes in the wrong place Dave :

"=COUNTIF(R[4]C:R[" & counter & "]C,""" & "d1"")"

-----Original Message-----
xl 2k
Win 2k

Trying to use VBA to enter a formula, must use RC
notiation so I can use variable number of rows, and then
will copy the formula using relative ranges and but still
mustuse a specific cell for the criteria.

sample snippet

Sub fixcount()
Dim counter As Integer
counter = 5
'what I want....
'Sheets("Test").Range("d3").FormulaR1C1 = "=COUNTIF(R[4]

C:R
[" & counter & "]C,""" & value in a fixed cell & ")"""

'what I have --doesn't work run time 1004
Sheets("Test").Range("d3").FormulaR1C1 = "=COUNTIF(R[4]C:R
[" & counter & "]C,""" & "d1" & ")"""
End Sub

Is my problem a mix of RC and the "D1" notations?
TIA Dave
.



  #4   Report Post  
Posted to microsoft.public.excel.programming
No Name
 
Posts: n/a
Default countif syntax VBA

thanks but not quite right yet

sample below
Sub Macro16()
Dim counter As Integer
counter = 20
ActiveCell.FormulaR1C1 = "=COUNTIF(R[4]C:R[" & counter
& "]C,""" & "d1"")"
End Sub

enter value of 6 in d1
put dummy data in range d4 to 20
run the code in cell D3 and count is zero.

It seems to read D1 as a text values instead of the value
in D1

Dave

-----Original Message-----
Just a few quotes in the wrong place Dave :

"=COUNTIF(R[4]C:R[" & counter & "]C,""" & "d1"")"

-----Original Message-----
xl 2k
Win 2k

Trying to use VBA to enter a formula, must use RC
notiation so I can use variable number of rows, and then
will copy the formula using relative ranges and but

still
mustuse a specific cell for the criteria.

sample snippet

Sub fixcount()
Dim counter As Integer
counter = 5
'what I want....
'Sheets("Test").Range("d3").FormulaR1C1 = "=COUNTIF(R[4]

C:R
[" & counter & "]C,""" & value in a fixed cell & ")"""

'what I have --doesn't work run time 1004
Sheets("Test").Range("d3").FormulaR1C1 = "=COUNTIF(R[4]

C:R
[" & counter & "]C,""" & "d1" & ")"""
End Sub

Is my problem a mix of RC and the "D1" notations?
TIA Dave
.

.

  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default countif syntax VBA

See my post for a tested version that works.

--
Regards,
Tom Ogilvy

wrote in message
...
thanks but not quite right yet

sample below
Sub Macro16()
Dim counter As Integer
counter = 20
ActiveCell.FormulaR1C1 = "=COUNTIF(R[4]C:R[" & counter
& "]C,""" & "d1"")"
End Sub

enter value of 6 in d1
put dummy data in range d4 to 20
run the code in cell D3 and count is zero.

It seems to read D1 as a text values instead of the value
in D1

Dave

-----Original Message-----
Just a few quotes in the wrong place Dave :

"=COUNTIF(R[4]C:R[" & counter & "]C,""" & "d1"")"

-----Original Message-----
xl 2k
Win 2k

Trying to use VBA to enter a formula, must use RC
notiation so I can use variable number of rows, and then
will copy the formula using relative ranges and but

still
mustuse a specific cell for the criteria.

sample snippet

Sub fixcount()
Dim counter As Integer
counter = 5
'what I want....
'Sheets("Test").Range("d3").FormulaR1C1 = "=COUNTIF(R[4]

C:R
[" & counter & "]C,""" & value in a fixed cell & ")"""

'what I have --doesn't work run time 1004
Sheets("Test").Range("d3").FormulaR1C1 = "=COUNTIF(R[4]

C:R
[" & counter & "]C,""" & "d1" & ")"""
End Sub

Is my problem a mix of RC and the "D1" notations?
TIA Dave
.

.





  #6   Report Post  
Posted to microsoft.public.excel.programming
No Name
 
Posts: n/a
Default countif syntax VBA

Thanks Tom, I suspected that it was due to the mix in
notations.

Dave


-----Original Message-----
You can't mix R1C1 notation and A1 notation in a single

formula

ActiveCell.FormulaR1C1 = "=COUNTIF(R[4]C:R[" & counter

& "]C,"""" &R1C4)"

all on one line worked for me.

--
Regards,
Tom Ogilvy



"Rog" wrote in

message
...
Just a few quotes in the wrong place Dave :

"=COUNTIF(R[4]C:R[" & counter & "]C,""" & "d1"")"

-----Original Message-----
xl 2k
Win 2k

Trying to use VBA to enter a formula, must use RC
notiation so I can use variable number of rows, and

then
will copy the formula using relative ranges and but

still
mustuse a specific cell for the criteria.

sample snippet

Sub fixcount()
Dim counter As Integer
counter = 5
'what I want....
'Sheets("Test").Range("d3").FormulaR1C1 = "=COUNTIF(R

[4]
C:R
[" & counter & "]C,""" & value in a fixed cell & ")"""

'what I have --doesn't work run time 1004
Sheets("Test").Range("d3").FormulaR1C1 = "=COUNTIF(R[4]

C:R
[" & counter & "]C,""" & "d1" & ")"""
End Sub

Is my problem a mix of RC and the "D1" notations?
TIA Dave
.



.

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
VBA syntax dhstein Excel Discussion (Misc queries) 3 March 13th 09 12:53 PM
syntax for countif when cells fall within a numerical range Tom L Excel Worksheet Functions 5 May 31st 08 03:22 AM
Need help with Syntax Marty Excel Programming 6 June 22nd 04 02:38 AM
CountIf: Syntax and Examples? Michael[_27_] Excel Programming 5 May 7th 04 08:31 PM
excel vba - COUNTIF syntax paku[_5_] Excel Programming 3 April 16th 04 03:09 AM


All times are GMT +1. The time now is 04:17 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"