Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/vba/15.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Excel R1C1,变量与等式中的数学_Excel_Vba_Variables - Fatal编程技术网

Excel R1C1,变量与等式中的数学

Excel R1C1,变量与等式中的数学,excel,vba,variables,Excel,Vba,Variables,尝试从变量和相对位置创建公式。 变量(X)是一个double以及RC[1](未设置但看起来像一个)将选择的单元格 如果我这样运行它,它会给出一个应用程序或对象定义的错误 Dim MIDDLEcounter As Integer Dim Xdatacell As String Dim Xdatacellvalue As Double Xdatacell = "B" & MIDDLEcounter (basicly 2 but changable) Range(Xdatacell).Sele

尝试从变量和相对位置创建公式。 变量(X)是一个double以及RC[1](未设置但看起来像一个)将选择的单元格

如果我这样运行它,它会给出一个应用程序或对象定义的错误

Dim MIDDLEcounter As Integer
Dim Xdatacell As String
Dim Xdatacellvalue As Double
Xdatacell = "B" & MIDDLEcounter (basicly 2 but changable)
Range(Xdatacell).Select
Xdatacellvalue = ActiveCell.Value

ActiveCell.FormulaR1C1 = "=RC[1] - " & Xdatacellvalue  & " "

尝试一些小的东西,看看它的工作。只写这一行:

Sub TestMe
    ActiveCell.FormulaR1C1 = "=RC[1] - " & "23.8"
End Sub
如果可行,问题可能在于从本地Excel语言到VBA的
Double
表示中:

Sub TestMe
    ActiveCell.FormulaR1C1 = "=RC[1] - " & Replace("23,8", ",", ".")
End Sub

最后,删除硬编码值并进行尝试

你能解释一下你的代码的目的是什么吗?也许包括所有相关的部分(请参阅)。首先,您在哪里设置变量的值?您必须在使用MIDDLEcounter之前为其指定一个值。是的,解决了这个问题(是关于Excel语言到VBA:),谢谢!