Pure Water
Pure Water

Reputation: 11

R1C1, variable and mathematics in eqation

Trying to create a a formula from a variable and relative location. Variable (X) is a double as well as the cell which RC[1] (isnt set but looks like one) will select

if I run it like this it gives out an application or object defined error.

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  & " "

Upvotes: 0

Views: 87

Answers (1)

Vityata
Vityata

Reputation: 43585

Try something small to see it working. Write only this line:

Sub TestMe
    ActiveCell.FormulaR1C1 = "=RC[1] - " & "23.8"
End Sub

If it works, probably the problem is in the presentation of the Double from the local Excel language to VBA:

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

At the end, remove the hardcoded value and give it a try.

Upvotes: 1

Related Questions