D
dgp
For the life of me I can't figure out what it wrong with a user-defined
function I am developing. The problem seems to be in the calculation of
"Distance" from elements of the arrays.
I'm also having problem transfering the ranges to the arrays when the
number of rows is large (~6000).
Any assistance would be greatly appreciated.
Thank you in advance,
Dave
Function IDW(rngX As Range, rngY As Range, rngXData As Range, rngYData
As Range, rngData As Range, Power as Double)
' Fill arrays by assigning ranges to variant variables
varX = rngX
varY = rngY
varXData = rngXData
varYData = rngYData
varData = rngData
NPoints = Application.Count(rngX)
NData = Application.Count(rngXData)
ReDim arrResult(NPoints)
For i = 1 To NPoints
For j = 1 To NData
Distance = Sqr((varX(i) - varXData(j)) ^ 2 _
+ (varY(i) - varYData(j)) ^ 2)
SumDataWeights = SumDataWeights + varData(j) / Distance ^
Power
SumDistWeights = SumDistWeights + 1 / Distance ^ Power
Next j
arrResult(i) = SumDataWeights / SumDistWeights
Next i
IDW = arrResult
End Function
function I am developing. The problem seems to be in the calculation of
"Distance" from elements of the arrays.
I'm also having problem transfering the ranges to the arrays when the
number of rows is large (~6000).
Any assistance would be greatly appreciated.
Thank you in advance,
Dave
Function IDW(rngX As Range, rngY As Range, rngXData As Range, rngYData
As Range, rngData As Range, Power as Double)
' Fill arrays by assigning ranges to variant variables
varX = rngX
varY = rngY
varXData = rngXData
varYData = rngYData
varData = rngData
NPoints = Application.Count(rngX)
NData = Application.Count(rngXData)
ReDim arrResult(NPoints)
For i = 1 To NPoints
For j = 1 To NData
Distance = Sqr((varX(i) - varXData(j)) ^ 2 _
+ (varY(i) - varYData(j)) ^ 2)
SumDataWeights = SumDataWeights + varData(j) / Distance ^
Power
SumDistWeights = SumDistWeights + 1 / Distance ^ Power
Next j
arrResult(i) = SumDataWeights / SumDistWeights
Next i
IDW = arrResult
End Function