AW: Spalte A + 2 ?
27.03.2007 21:14:09
Alex
Hallo Willmes
Ich habe da mal 2 Fuctionen geschrieben. Mit der einen kanst Du zb. die Spalte AX in eine Zahl umwandeln und mit der andern die Zahl 27 in AA
Mit den zewi Prozeduren kannst du das Problem lösen.
Public Function ColumnIndexToString(Index As Integer) As String
Dim sTmp As String
Dim iCounter As Integer
Dim iMod As Integer
' Ermitteln wie oft das ABC im Index vorkommt
iCounter = WorksheetFunction.RoundDown(CDbl(Index / 26), 0)
iMod = Index Mod (26)
If iMod = 0 Then
iMod = 26
iCounter = iCounter - 1
End If
If Not iCounter = 0 Then
sTmp = Chr(Asc("@") + iCounter)
End If
ColumnIndexToString = sTmp & Chr(Asc("@") + iMod)
End Function
Public Function StringToColumnIndex(Key As String) As Integer
Dim iResult As Integer
If Len(Key) = 1 Then
iResult = Asc(UCase(Key)) - Asc("@")
Else
iResult = (Asc(UCase(Mid(Key, 1, 1))) - Asc("@")) * 26
iResult = iResult + (Asc(UCase(Mid(Key, 2, 1))) - Asc("@"))
End If
StringToColumnIndex = iResult
End Function
Der aufruf damit Du den Buchstaben 2 Spalten neben der Spalte BI bekommst sieht dann so aus.
Dim Spalte as String
Spalte = ColumnIndexToString( StringToColumnIndex("BI")+2)
Spalte ist dann BK
Gruss Alex