Hi, this function returns a script, which contains the value of the columns for excel. for example, if you call MyColumn(1), you'll get the string "A". If you call MyColumn(27), you'll get "AA".
Function myColumn(column As Integer) As String
'******************************
' author: tomas mezger
' tmezger_at_ffe.de
' date: 12.10.2007
'******************************
' this function returns a script, which contains the value of
' the columns for excel
' for example,
' MyColumn(1) = A
' MyColumn(26) = Z
' MyColumn(27) = AA
' MyColumn(100) = CV
' MyColumn(256) = IV
' MyColumn(257) = NULL <--- Error. Excel has only 256 columns!!!!
Dim column1 As Integer
Dim column2 As Integer
column2 = (column - 1) Mod 26 + 65
'MyColumn2 = Chr(column2)
' das liefert das hintere Teil des Bezuges
If column > 256 Then
myColumn = "NULL"
MsgBox ("Error, column must be <= 256 !!!")
Else
If column <= 26 Then
myColumn = Chr(column2)
Else
column1 = WorksheetFunction.RoundDown(((column - 1) / 26), 0) + 64
myColumn = Chr(column1) & Chr(column2)
End If
End If
End Function
No comments:
Post a Comment