Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

using CountIF in formula 1

Status
Not open for further replies.

jmstarbuck

Programmer
Aug 11, 2003
90
US
I am trying to set the formula of a cell in my vb code. Here's what I am doing:
Code:
 Dim myexpr As String
 Dim myrange As String
    
    myexpr = """<>0"""
    myrange = "D5:D" & lastrow
    ActiveCell.FormulaR1C1 = "=CountIf(" & myrange & ", " & myexpr & " )"

What ends up in the formula of the cell is:
=COUNTIF('D5':'D301', "<>0" )

What am I doing wrong? How can I get rid of the single quotes?

Any suggestions appreciated!
 



Code:
    ActiveCell.[b]Formula[/b] = "=CountIf(" & myrange & ", " & myexpr & " )"

Skip,

[glasses]Just traded in my old subtlety...
for a NUANCE![tongue]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top