Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

VBA keeps changing the formula I put into a range

So I have a relatively simple code that puts a formula (that refers to a different sheet in the same workbook) into a range.

Range(Selection, Selection.End(xlUp)).Formula2R1C1 = "=XLOOKUP(RC[-1],'Trade Summary'!X:X,'Trade Summary'!H:H)"

My problem is that after I run the code VBA changes the formula into for example:

=XLOOKUP(E15,'Trade Summary'!X:(X),'Trade Summary'!H:(H))

which makes it not working due to the brackets around ranges.
Is there a way to avoid this?

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

It seems strange, but you use C24 to refer to all of column X and C8 to refer to all of column H when using R1C1 notation. So adjust your formulas as follows:

"=XLOOKUP(RC[-1],'Trade Summary'!C24,'Trade Summary'!C8)"

Here C24 does not mean the cell at the intersection of column C and Row 24, it means "Column 24" which is all of column X.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading