Domanda

Is there a quick way to use Excel's Trend function in Access?

Specifically, I want to use values that I have in the Access database to project values out for 24 months. I also want to update the database/table with values that were calculated in a new column.

I am a noob.

È stato utile?

Soluzione

"Is there a quick way to use Excel's Trend function in Access?"

It's possible. But quick, maybe not so much.

Give the Trend() function arrays of known X and Y values, and another array for the extended X range for which you want to predict Y values. And Trend() will give you back another array containing the predicted Y values.

This code worked in Access 2007 with a reference to the Excel object library.

Dim knownX, knownY, newX, TrendY
Dim i As Long

knownY = Array(2, 4, 5)
knownX = Array(1, 2, 3)
newX = Array(4, 5)
TrendY = Excel.WorksheetFunction.Trend(knownY, knownX, newX)
For i = LBound(TrendY) To UBound(TrendY)
    Debug.Print "X: " & newX(i - 1), "Y: " & TrendY(i)
Next

I used Array() to create the input arrays, but you want your arrays to contain values from a table, so that will be more effort.

Also beware that Access arrays are (generally) zero-based, but Trend() returned a one-based array. Make sure you know which you're dealing with.

And, since you intend to store the predicted Y values, you will have even more work to do.

After thinking about this some more, I suspect it might be easier to export your Access data to an Excel workbook, then use COM automation to modify the sheet in Excel, save the modified workbook, and finally pull the sheet data back into Access.

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top