dreid1011
Well-known Member
- Joined
- Jun 4, 2015
- Messages
- 3,645
- Office Version
- 365
- Platform
- Windows
Good morning,
I have a UDF that is returning a #NAME error, and I cannot figure out why.
This is what I am doing(or trying):
Averaging cells 1 and 2, then squaring it. Averaging cells 2 and 3, then squaring it. 3 and 4, 4 and 5, etc and summing all of them until the end of the row.
Being that it's a UDF, there is no help on the error, and I can't seem to use F8 to step through it in the VBA editor. Any thoughts?
I have a UDF that is returning a #NAME error, and I cannot figure out why.
This is what I am doing(or trying):
Averaging cells 1 and 2, then squaring it. Averaging cells 2 and 3, then squaring it. 3 and 4, 4 and 5, etc and summing all of them until the end of the row.
Code:
Function ColCalcs(ByVal cRange As String) As Double
Dim ws As Worksheet
Set ws = ActiveSheet
Dim cRow As Long
Dim cCol As Long
cRow = ws.Range(cRange).Row
cCol = ws.Range(cRange).Column
Dim lastCol As Long
lastCol = ws.Cells(cRow, Columns.Count).End(xlLeft).Column
Dim i As Long
i = cCol
Dim cValue As Double
cValue = 0
For i = i To lastCol
cValue = cValue + (((ws.Cells(cRow, cCol).Value + ws.Cells(cRow, cCol + 1).Value) / 2) ^ 2)
cCol = cCol + 1
Next
ColCalcs = cValue
End Function
Being that it's a UDF, there is no help on the error, and I can't seem to use F8 to step through it in the VBA editor. Any thoughts?