Re: Selecting Columns in Excel by Mark
Mark
Mon Mar 20 07:29:13 CST 2006
Function ConvertToLetter(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
or
Function Num2Let(L As Long) As String
Dim s0 As String, s1 As String, S2 As String, s3 As String
If L > 18278 Then s0 = Chr((Int((L - 18279) / 17576) Mod 26) + 65)
If L > 702 Then s1 = Chr((Int((L - 703) / 676) Mod 26) + 65)
If L > 26 Then S2 = Chr(Num2Let & (Int((L - 27) / 26)) Mod 26 + 65)
s3 = Chr(((L - 1) Mod 26) + 65)
Num2Let = s0 & s1 & S2 & s3
End Function
Regards
Mark Dormer
"DaleM" <dmenken2@comcast.net> wrote in message
news:1142631306.942427.278260@i39g2000cwa.googlegroups.com...
>I have a vbs script that is placing data into multiple rows and columns
> using loops and referencing cells via a row number and column number.
> Is there an easy way to change the column number into the Excel
> 'Letter' format? ie: 1=A, 2=B I need to select the column within my
> script and it does not seem to like numbers, just the letter.
>
> ' this works
> oExcel.Columns("A:A").Select
>
> ' this causes an error
> oExcel.Columns("1:1").Select
>
>
> Any help is appreaciated.
>
> Dale
>