Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2
Default Range.FormulaArray drops relative reference ?

Hi
I am trying to apply a formula to the FormulaArray property of a range in
VBA code and I have trouble with the cell references are not updated as is
usually the case. Here is an example. It has been heavily simplified to
emphasize the problem but I need to put a complex array formula in hundreds
of rows. The following example could be used to get the sum of values in
NamedRange greater than the value in the left column.

The following VBA code works correctly:

Names.Add Name:="NamedRange" _
, RefersToR1C1:=ActiveSheet.Range(SomeRange)

ActiveSheet.Cells(2,2).FormulaArray = _
"=SUM(IF(NamedRangeRC[-1],NamedRange))"
ActiveSheet.Cells(3,2).FormulaArray = _
"=SUM(IF(NamedRangeRC[-1],NamedRange))"

Resulting formulas
B2 : =SUM(IF(NamedRangeA2,NamedRange))
B3 : =SUM(IF(NamedRangeA3,NamedRange))

The following does not work.
ActiveSheet.Range(Cells(2,2),Cells(3,2)).FormulaAr ray = _
"=SUM(IF(NamedRangeRC[-1],NamedRange))"

The resulting formula in B2 and B3 is exactly the same.
B2 : =SUM(IF(NamedRangeA2,NamedRange))
B3 : =SUM(IF(NamedRangeA2,NamedRange)) ' <Wrong reference

I have lost the relative reference to the left column in the second
formula(A3 is not there). Now, how do I get the relative reference to work
correctly ? Do I have to loop through all the cells to insert a correct
FormulaArray ? Is there a magic trick ?

TIA
Stephane
Excel 2002
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default Range.FormulaArray drops relative reference ?

Yes. You can have single cell formula arrays (what you want) or multiple
cell formula arrays (what you are getting). So you will need to loop and
apply each cell individually

--
Regards,
Tom Ogilvy

"SPaquin" wrote in message
...
Hi
I am trying to apply a formula to the FormulaArray property of a range in
VBA code and I have trouble with the cell references are not updated as is
usually the case. Here is an example. It has been heavily simplified to
emphasize the problem but I need to put a complex array formula in

hundreds
of rows. The following example could be used to get the sum of values in
NamedRange greater than the value in the left column.

The following VBA code works correctly:

Names.Add Name:="NamedRange" _
, RefersToR1C1:=ActiveSheet.Range(SomeRange)

ActiveSheet.Cells(2,2).FormulaArray = _
"=SUM(IF(NamedRangeRC[-1],NamedRange))"
ActiveSheet.Cells(3,2).FormulaArray = _
"=SUM(IF(NamedRangeRC[-1],NamedRange))"

Resulting formulas
B2 : =SUM(IF(NamedRangeA2,NamedRange))
B3 : =SUM(IF(NamedRangeA3,NamedRange))

The following does not work.
ActiveSheet.Range(Cells(2,2),Cells(3,2)).FormulaAr ray = _
"=SUM(IF(NamedRangeRC[-1],NamedRange))"

The resulting formula in B2 and B3 is exactly the same.
B2 : =SUM(IF(NamedRangeA2,NamedRange))
B3 : =SUM(IF(NamedRangeA2,NamedRange)) ' <Wrong reference

I have lost the relative reference to the left column in the second
formula(A3 is not there). Now, how do I get the relative reference to work
correctly ? Do I have to loop through all the cells to insert a correct
FormulaArray ? Is there a magic trick ?

TIA
Stephane
Excel 2002



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 22
Default Range.FormulaArray drops relative reference ?

Hello Stephane,

I am reviewing the issue thread. Tom has given suggestion on it. Have you
successfully resovled the problem? If not, please feel free to reply here
and we are glad to work with you on it.

Thanks very much.

Best regards,
Yanhong Huang
Microsoft Community Support

Get Secure! ¨C www.microsoft.com/security
Register to Access MSDN Managed Newsgroups!
-http://support.microsoft.com/default.aspx?scid=/servicedesks/msdn/nospam.as
p&SD=msdn

This posting is provided "AS IS" with no warranties, and confers no rights.

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2
Default Range.FormulaArray drops relative reference ?

Even thouh the solution is not what I wanted the program to do, yes, Tom has
answered my question.
Stephane

"Yan-Hong Huang[MSFT]" wrote:

Hello Stephane,

I am reviewing the issue thread. Tom has given suggestion on it. Have you
successfully resovled the problem? If not, please feel free to reply here
and we are glad to work with you on it.

Thanks very much.

Best regards,
Yanhong Huang
Microsoft Community Support

Get Secure! ¨C www.microsoft.com/security
Register to Access MSDN Managed Newsgroups!
-http://support.microsoft.com/default.aspx?scid=/servicedesks/msdn/nospam.as
p&SD=msdn

This posting is provided "AS IS" with no warranties, and confers no rights.


  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 225
Default Range.FormulaArray drops relative reference ?

Hi Stephane,

Thanks for your resposne!
If you still have any concern on this issue, please feel free to post here.




Best regards,

Peter Huang
Microsoft Online Partner Support

Get Secure! - www.microsoft.com/security
This posting is provided "AS IS" with no warranties, and confers no rights.



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
Relative Range Reference in a sumifs formula cbotos Excel Worksheet Functions 6 April 1st 10 02:59 AM
Range of cells: Convert relative reference into absolute Igor Excel Discussion (Misc queries) 5 September 30th 08 01:16 AM
Excel changes chart source data. Drops the Filename reference from ybkusz Excel Discussion (Misc queries) 0 February 1st 08 03:14 AM
unable to set the FormulaArray property of the Range class jim kozak Excel Programming 4 March 29th 05 02:15 PM
unable to set formulaarray of range class ERROR when using Conditional Sum John H.[_2_] Excel Programming 1 September 25th 03 09:55 PM


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