evaluate R1C1 excel function inside of VBA

white_flag

Active Member
Joined
Mar 17, 2010
Messages
331
Hello

I like to evaluate an excel function inside of VBA that will generate an graphic.
the excel function is like this:

Code:
With rTopLeft.Offset(n, m)
formula1 = "INDEX(m_cla,MATCH(rc" & rTopLeft.Column & ",INDEX(m_cla,,1),1),IF(ISNA(MATCH(r" & rTopLeft.Row & "c,INDEX(m_cla,1,))),1,MIN(IF(ISNA(MATCH(r" & rTopLeft.Row & "c,INDEX(m_cla,1,),0)),MATCH(r" & rTopLeft.Row & "c,INDEX(m_cla,1,))+1,MATCH(r" & rTopLeft.Row & "c,INDEX(m_cla,1,),0)))))"
formula2 = "INDEX(pre,IF(ISNA(MATCH((2*r" & rTopLeft.Row & "c+rc" & rTopLeft.Column & "),INDEX(pre,,1))),1,MIN(IF(ISNA(MATCH((2*r" & rTopLeft.Row & "c+rc" & rTopLeft.Column & "),INDEX(pre,,1),0)),MATCH((2*r" & rTopLeft.Row & "c+rc" & rTopLeft.Column & "),INDEX(pre,,1))+1,MATCH((2*r" & rTopLeft.Row & "c+rc" & rTopLeft.Column & "),INDEX(pre,,1),0)))),2)"


.FormulaR1C1 = "=(" & formula1 & "+" & formula2 & ")"

..etc

'graphic

Dim f1 As Double, f2

            
f1 = f1 + Evaluate(formula1)
f2 = f2 + Evaluate(formula2)

Dim ChartObj As ChartObject
Dim ChartSeries As Series
 
Set ChartObj = ActiveSheet.ChartObjects.Add(Left:=100, Width:=550, Top:=75, Height:=325)
Set ChartSeries = ChartObj.Chart.SeriesCollection.NewSeries
With ChartSeries
            .Type = xlPie
            .Values = Array(f1, f2)
            .XValues = Array("value 1", "value 2")
            
End With
but because is an R1C1 formula I receive error (type mismatch). can I rewrite formula 1 & formula 2 (just for the graphic part) ? to have the values from excel.

thank you
 
so it is like this:
this
Code:
f1 = f1 + Evaluate(formula1)
become this:

Code:
f1 = f1 + Evaluate(Application.ConvertFormula(formula1, xlR1C1, xlA1))
Application.ConvertFormula will convert R1C1 in cell.address.
this fix my problem.
 
Upvote 0
...
Code:
f1 = f1 + Evaluate(Application.ConvertFormula(formula1, xlR1C1, xlA1))
Application.ConvertFormula will convert R1C1 in cell.address.
this fix my problem.

Hi

Caveat:

Your R1C1 formula has relative addresses.

If you want to convert a relative formula in R1C1 notation to A1 notation, you must specify to which cell the formula is relative to, or else vba assumes you want the formula relative to the activecell which may not be what you want.
 
Upvote 0

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top