2

I'm having a particulary awful time understanding what goes wrong here.

I would like to enter the following formula via VBA:

Range("C8").Select
ActiveCell.FormulaR1C1 = "=MODE.SNGL('Data'!D:D)"

Now, the problem is that VBA instead outputs it as:

=MODE.SNGL('Data'!D(D)

I tried using chr(58) and also using ' to escape, but no cherry. Could someone tell me what I am doing wrong?

3
  • 1
    what code did you use? Commented Jul 1, 2013 at 13:37
  • 1
    made an edit to show more of the code. Commented Jul 1, 2013 at 13:39
  • Others have answered but not that you could use just ActiveCell.Formula = "=MODE.SNGL(Data!D:D)", the pair of ' are redundant Commented Jul 1, 2013 at 13:45

2 Answers 2

3

Use this instead:

ActiveCell.Formula = "=MODE.SNGL('Data'!D:D)"

Or if you need to use .FormulaR1C1 property you could do it this way:

ActiveCell.FormulaR1C1 = "=MODE.SNGL('Data'!C4:C4)"
Sign up to request clarification or add additional context in comments.

2 Comments

fyi since the activecell was in column c the r1c1 version ought to refer to 'Data'!C[1]:C[1] or Data!C4:C4 for absolute references
@JosieP, you right, I improved answer accordingly, thank you!
2

if you use FOrmulaR1C1 you have to pass an R1C1 style reference not A1 style. replace that code by

Range("C8").Formula = "=MODE.SNGL('Data'!D:D)"

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.