I am trying to
- pass two ranges - multiple column single row - to a user defined function in Excel 2007,
then assigning it to an array for processing.
Function MAE(actualData As Range, forecastData As Range) As Double
Dim data Dim forecast Dim error As Double Dim average As Double Dim i As Long data = Application.Transpose(actualData) forecast = Application.Transpose(forecastData) average = 0 error = 0 For i = 1 To UBound(data) error = data(i) - forecast(i) If error < 0 Then error = error * -1 End If average = error + average Next i MAE = average / UBound(data) End Function
I have posted a thread earlier in this forum, here is the link
In that thread I asked about passing a single column as Range to a user defined function. After your suggestions, I modified the code and it is working perfectly when I pass two single columns.
But when I pass two rows then it is not working. I am getting #Value error. Any suggestions about this?

A1:A8andB1:B8are the ranges that you want to compare, you can calculate the mean absolute difference by entering=AVERAGE(ABS(B1:B8-A1:A8))as an array formula in a worksheet cell (that is, by pressing Ctrl+Shift+Enter instead of just Enter after typing in the formula).