View Single Post
  #1   Report Post  
Posted to microsoft.public.excel.programming
falloutx falloutx is offline
external usenet poster
 
Posts: 1
Default Macro to add count forumla with dynamic range


I am trying to use macro to add a COUNT() formula with a dynamic range.


A small example is

Code:
--------------------
Range("P7").Select
dynamicRow = 8 'may change dynamically
fixedStartRow = 5 - Row
ActiveCell.FormulaR1C1 = "=SUM("+fixedStartRow+":R[-1]C)"
--------------------


But the code above does not work!


Then I thought I can work ard iby making the ActiveCell dynamic.

Code:
--------------------
Range("P7").Select 'Selected cell may change dynamically
ActiveCell.FormulaR1C1 = "=SUM(P5:R[-1]C)"
--------------------


But this code produce the following in the cell box in excel sheet.
=SUM('P5':P6)


Why does it have 'P5' insteadd of just P5


Please advise! thanks!


--
falloutx
------------------------------------------------------------------------
falloutx's Profile: http://www.excelforum.com/member.php...o&userid=30560
View this thread: http://www.excelforum.com/showthread...hreadid=551270