简体   繁体   中英

Excel 2010 VBA “=IFERROR…”

I'm using VBA to introduce formulas in my local database regarding some conditions. Here is an example of the code I'm using:

Range("CP" & l).Formula = "=IFERROR(((T" & l & "*6)-SUM(U" & l & ":Z" & l & "))/(T" & l & "*6);"""")"

Were "l" is my first blank row (it's working)

The formula is working very well, but the problem I have is that the code is returning only the value of the result in my cell, but I would like to see the whole formula in my cell.

Is it something that can be possible to do ?

* The real problem is that the formula IS NOT in the formula bar. The Code write the score, but not the formula. If I do a test with

Range("CP" & l).Formula = "=((T" & l & "*6)-SUM(U" & l & ":Z" & l & "))/(T" & l & "*6)"

I see the formula in the formula bar.

I really don't understand...

Thanks :)

Marie

but I would like to see the whole formula in my cell.

To display the formula in the cell instead of the values, you have 3 options

  1. Format the cells as text and then use the code which you have.

    Range("CP" & l).Formula = "=IFERROR(((T" & l & "*6)-SUM(U" & l & ":Z" & l & "))/(T" & l & "*6);"""")"

  2. Change .Formula to .Value and add a ' before the = sign

    Range("CP" & l).Value = "'=IFERROR(((T" & l & "*6)-SUM(U" & l & ":Z" & l & "))/(T" & l & "*6);"""")"

  3. Activate the option File Tab | Options | Advanced | "Show Formulas in cells instead...." File Tab | Options | Advanced | "Show Formulas in cells instead...."

在此处输入图片说明

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