简体   繁体   English

在VBA Excel中编写公式

[英]Write formula in VBA Excel

I have troubles with writing formula in Excel VBA. 我在用Excel VBA编写公式时遇到麻烦。

Sub Macro()
  valueA1 = Range("A1").Value
  Range("C1").Formula = "=RC[-1]*" & valueA1
End Sub

At the end I want formula in cell C1 to be written as =B1*0,5 , if value in B1 is 0,5 . 最后,如果B1中的值为=B1*0,5 ,我希望单元格C1中的公式写为=B1*0,5 0,5

Thaks for the help! 谢谢帮助!

Excel doesn't like foreign languages. Excel不喜欢外语。 You will need to use FormulaR1C1Local : 您将需要使用FormulaR1C1Local

Range("C1").FormulaR1C1Local = "=RC[-1]+" & valueA1

or maybe 或者可能

Range("C1").FormulaR1C1Local = "=RC[-1]*" & valueA1

if you are trying to multiply B1*A1. 如果您要乘以B1 * A1。 (Your question says multiply, your code says add.) (您的问题说乘,代码说加。)

That should cause it to accept "0,5" as a valid number. 那应该使它接受"0,5"作为有效数字。

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

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