Videos
One thing I spotted off the bat:
If Cells(row, index).Value = name Then
The variable passed to the function is named rowNumber, not row. Change that line to:
If Cells(rowNumber, index).Value = name Then
edit:
One other thing to note is that your function never actually stops on its own. The only reason it ever ends is because it runs into an application defined error when trying to read column 16385 (because Excel is limited to 16384 columns*), which immediately kills the function, returning a #VALUE error.
The following revision prevents that and returns a -1 if the requested column name is not found:
Option Explicit
Function FindColumnIndex(name As String, rowNumber As Integer) As Integer
Dim index As Integer
index = 1
Dim found As Boolean
found = False
FindColumnIndex = -1
Do While found = False
If Cells(rowNumber, index).Value = name Then
FindColumnIndex = index
found = True
End If
index = index + 1
If index > 16384 Then Exit Do
Loop
End Function
[ * Excel 2007 is thus limited, anyway. I have no idea if newer versions have larger limits or not.]
If Cells(row, index).Value = name Then
did you mean:
If Cells(rowNumber , index).Value = name Then
Anyway, there are functions to do this, something like MATCH, INDEX & Co.
If you run the following test:
Sub Test()
Dim d As Double: d = 0.5 + 0.00024575 * 10000000
Debug.Assert d = Int(d)
Debug.Assert 0.5 + 2457.5 = Int(0.5 + 2457.5)
Debug.Assert 0.5 + 0.00024575 * 10000000 = Int(CDbl(0.5 + 0.00024575 * 10000000))
Debug.Assert 0.5 + 0.00024575 * 10000000 = CDbl(0.5 + 0.00024575 * 10000000)
Debug.Assert 0.5 + 0.00024575 * 10000000 = VBA.Int(0.5 + 0.00024575 * 10000000)
Debug.Assert 0.5 + 0.00024575 * 10000000 = Int(0.5 + 0.00024575 * 10000000)
End Sub
You will see that only the last Assert fails. This is probably a compiler bug.
Note that Int is not the same as VBA.Int.
Edit #1
As suggested in the comments by @GSerg, it appears that the Int method (not VBA.Int) does indeed calculate at compile time and it probably uses a different floating point precision. For example:
Option Explicit
#Const Test = Int(12.5)
Sub TestPrecompiler()
#If Test = 12 Then
Debug.Print "Int method calculates at compile time"
#End If
End Sub
I ran in to this issue recently and I found that using a CStr wrapper around the expression resolves the issue:
? Int(0.5 + 0.00024575 * 10000000)
2457
? Int(CStr(0.5 + 0.00024575 * 10000000))
2458
I also found that VBA.Int does not work, not does a CDbl wrapper:
? Int(100 * 307.09)
30708
? VBA.Int(100 * 307.09)
30708
? Int(CDbl(100 * 307.09))
30708
? Int(CStr(100 * 307.09))
30709