简体   繁体   中英

Excel macro adding formula to cell not working

Aplogies for typos.. Having the write this on my phone due to restrictions at work. I've got a macro in excel that is as part of the application adding a formula to a cell

ActiveCell.FormulaR1C1 = "=IF(COUNTA([@[TABLECELL]])=0,"""",VLOOKUP([@[TABLECELL]],Sheet1!K:L,2,FALSE))"

The macro gets inserted but it's putting a bracket around the L. " Sheet!K:(L) " this means the formula doesn't work. Totally stumped why it's doing this.

So im not sure what you think by using [@[TABLECELL]], but take a look at this

ActiveCell.FormulaR1C1 = "=IF(COUNTA(R[-4]C[-1]:R[-4]C[2])=0,"""",VLOOKUP(R[1]C[-1]:R[2]C[2],Sheet1!C[5]:C[6],2,FALSE))"

When you are using formulaR1C1 you need to use proper cell adressing. So feel free to change cell adreses in COUNTA and VLOOKUP to your tablecell and i think this should work

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