Using ActiveCell.FormulaR1C1 = and =COUNTIF

Joined
Nov 12, 2008
Messages
2
Reaction score
0
Hi

I want to use the following code so that the active cell is populated with the formular =COUNTIF(M2:M" & rowCount & ", "" * "")

Sub Macro1()
Dim theRange As String
Dim rowCount As Integer
rowCount = rowCount + 10 ' Set rowcount
theRange = "M" & rowCount
Range(theRange).Select
ActiveCell.FormulaR1C1 = "=COUNTIF(M2:M" & rowCount & ", "" * "")"
With ActiveCell.Characters(Start:=1, Length:=8).Font
.Name = "Arial"
.FontStyle = "Bold"
.Size = 12
.ColorIndex = xlAutomatic
End With
End Sub

Unfortunately I get the following result. =COUNTIF('M2':'M40', " * ")

Close, however no cigar!!! How do I get rid of the quotes around the M2 & M40??
 
Joined
Dec 5, 2008
Messages
6
Reaction score
0
Sub Macro1()
Dim rng As Range

'create range object
Set rng = Thisworkbook.Worksheets("Sheet1").Range("M10")

'with range
With rng
.FormulaR1C1 = "=COUNTIF(""M2:M""" & rowCount & ", "" * "")"
With .Font
.Name = "Arial"
.FontStyle = "Bold"
.Size = 12
.ColorIndex = xlAutomatic
End With
End With

'delete object -> free memory
Set rng = Nothing

End Sub
 
Joined
Nov 12, 2008
Messages
2
Reaction score
0
Hi All

I finally worked out the answer....Well an answer.

Instead of using "FormulaR1C1" I just used "Formula" and it now works fine. Thanks for the additional information about deleting the object to free up memory....

Cheers
Mark
 
Joined
Apr 19, 2008
Messages
4,081
Reaction score
1
Well there you go then...Job done..Thanks for sharing your solution with us...Always good to know what results people came out with in the end....:thumb: :thumb:
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top