I am using a function that I copied from Microsoft that takes a column number and reassigns the column letters. I need to do this to create a formula. I have researched all day and cannot pinpoint the cause of my errors (I also tried to accomplish this as a sub proc). The function is in its own module. I tested it and it works fine:
Function ConvertToLetter(ByRef iCol As Integer) As String
Dim iAlpha As Integer
Dim iRemainder As Integer
iAlpha = Int(iCol / 27)
iRemainder = iCol - (iAlpha * 26)
If iAlpha > 0 Then
ConvertToLetter = Chr(iAlpha + 64)
End If
If iRemainder > 0 Then
ConvertToLetter = ConvertToLetter & Chr(iRemainder + 64)
End If
End Function
The code that is giving me an error is:
For groups = 1 To i ' level 1 grouping
For iCol = 24 To 136
rCol = ConvertToLetter(iCol)
Cells(Start(groups) - 1, rCol).Formula = "=COUNTA(" & rCol & Start(groups) & ":" & rCol & Finish(groups) & ")"
Next
Next
I tried substituting the function into the formula itself:
Cells(Start(groups) - 1, ConvertToLetter(iCol)).Formula = "=COUNTA(" & ConvertToLetter(iCol) & Start(groups) & ":" & ConvertToLetter(iCol) & Finish(groups) & ")"
The debugger made it past the first function call, but not the second & third. The errors I receive are types of "expecting a variable or procedure, not module." With the second case, I get other errors, and my head is so fuzzy, I cannot recall them.
Any help is greatly appreciated. I have run out of ideas. Thanks so much!