简体   繁体   English

Excel宏将公式结果写入单元格

[英]Excel Macro to write a formula result to a cell

I know how to write a formula to cell in a MACRO, but i need to write the output of this formula to the cell 我知道如何在宏中将公式写入单元格,但是我需要将此公式的输出写入单元格

Rng.Offset(0, 1).Formula = "=CONCATENATE(IF(RC[-1]<>"""",RC[-2]& _ MID(CELL(""filename"",RC),FIND(""]"",CELL(""filename"",RC))+1,256),""""),""_"",RC[-1])"

without using 不使用

Rng.Offset(0, 1).Copy
Rng.Offset(0, 1).PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, _ SkipBlanks:=False, Transpose:=False

I always just overwrite the value of the cell with its current value, so for example: 我总是只用当前值覆盖单元格的值,例如:

Rng.Offset(0, 1).Formula = "=CONCATENATE(IF(RC[-1]<>"""",RC[-2]& _
    MID(CELL(""filename"",RC),FIND(""]"",CELL(""filename"",RC))+1,256),""""),""_"",RC[-1])"
Rng.Offset(0, 1).Value = Rng.Offset(0, 1).Value

This will remove the formula from the cell and simply replace it with the value calculated by the formula. 这会将公式从单元格中删除,只需将其替换为公式计算出的值即可。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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