Excel/How to enter an Excel formula in a macro without using the string format?
Expert: Jan Karel Pieterse - 7/9/2009
QuestionHi
I am trying to calculate polynomial coefficients in excel. I can write
ActiveCell.FormulaR1C1 = "=INDEX(LINEST(R2C4:R1005C4,R2C6:R1005C6^{1,2,3,4,5,6}),1)"
but I want to specify the range rather than having to say "R2C4:R1005C4". How can I do it? One way I can think is to make the string programatically but that doesnt sound like good.
Thanks in advance,
Kaushalya
AnswerHi Kaushalya,
You could do something like this:
Sub Example()
Dim oRange As Range
On Error Resume Next
Set oRange = Application.InputBox("Please select cells", "Select cells for formula", , , , , , 8)
If Not oRange Is Nothing Then
ActiveCell.Formula = "=INDEX(LINEST(" & oRange.Address & ",F2:F1000^{1,2,3,4,5,6}),1)"
End If
End Sub
About Excel
This topic answers questions related to Microsoft Excel spreadsheet (or workbook) stand-alone or Mircrosoft Office Excel including Excel 2003, Excel 2007, Office 2000, and Office XP. You can get Excel help on Excel formulas(or functions), Excell macros, charting in Excel, advanced features, and the general use of Excel. This does not provide a general Excel tutorial nor the basics of using a spreadsheet. It provides specific answers to using Microsoft Excel only. If you do not see your
Excel question answered in this area then please ask an Excel question here