22

I'm using VBA, and I need to insert an array formula (the one that if I'm writing it manually, I'll press Ctrl+Shift+Enter and not just Enter). When I'm inserting it like a regular formula it doesn't work, neither when I put it with {} around it... What's the correct way of writing that formula using VBA?

The formula is this:

 =INDEX(subset!R1C1:R2472C10,MATCH(1,(RC1=subset!C1)*(RC2=subset!C2)*(RC5=subset!C5)*(RC6=subset!C6),0),10)  
1
  • 4
    Assigning an array formula to a cell or range uses the Range("A1").FormulaArray = "<the formula>" syntax. It does not matter whether you have the formula in xlA1 or xlR1C1 format. Commented Dec 22, 2014 at 14:04

2 Answers 2

30

You're looking for the FormulaArray property that you can set for a cell like so:

Range("A1").FormulaArray = "=INDEX(subset!R1C1:R2472C10,MATCH(1,(RC1=subset!C1)(RC2=subset!C2)(RC5=subset!C5)*(RC6=subset!C6),0),10)"

See the documentation here: http://msdn.microsoft.com/en-us/library/office/ff837104%28v=office.15%29.aspx

Sign up to request clarification or add additional context in comments.

1 Comment

Very good. But how do you do it R1 C1 which is what I needed...
1

FormulaArray unfortunately does not preserve relative cell referencing when applied to a range as expected with FormulaR1C1. To keep the cell referencing relative in a vertical range you can use FillDown.

First enter the Array Formula in the first row of the range:

Range("A1").FormulaArray = "=SUM((R1C5:R2C10 = ""INCLUDE"") * RC5:RC10)

Then Fill Down the desired range:

Range("A1:A10").FillDown

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.