简体   繁体   中英

Inserting formula in excel cell with VBA gone wrong?

It seems that the formula I'm trying to insert using VBA isn't inserted correctly:

Range("H3").Select
ActiveCell.FormulaR1C1 = "=INDEX(MIBIE!D:D,MATCH(A3,MIBIE!A:A,0))"

What I end up with in my cell is this:

=INDEX(MIBIE!D:(D);MATCH('A3';MIBIE!A:(A);0))

Which of course doesn't work, but what I'd need is the following:

=INDEX(MIBIE!D:D;MATCH(A3;MIBIE!A:A;0))

Any ideas how to fix this? I'm unfortunately unable to use cell reference using C[#] and R[#] as I have many cells I want to edit and it is unable to use columns and rows as a reference, but only the letters of those.

Thanks in advance :)

Use this line instead:

ActiveCell.Formula = "=INDEX(MIBIE!D:D,MATCH(A3,MIBIE!A:A,0))"

If you wanted to set the FormulaR1C1 then you'd have to write something like this:

ActiveCell.FormulaR1C1 = "=INDEX(MIBIE!C[3],MATCH(R[2]C,MIBIE!C,0))"

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM