AW: letzte Zelle in bestimmter Spalte ermitteln
06.12.2005 23:52:25
Erich
Hallo Erwin,
tut diese Prozedur, was du möchtest?
Option Explicit
Sub SortLetzte2()
Dim strSp$, intSp%, lngLRow&, intUeb&
intUeb = 1 ' Anzahl Zeilen für Spaltenüberschrift (0 für ohne)
strSp = InputBox("Nach welcher Spalte soll sortiert werden?", _
"Sortierung nach den letzten beiden Stellen", "F")
intSp = SpNumm(strSp)
' letzte Zeile der Spalte
lngLRow = Cells(Rows.Count, intSp).End(xlUp).Row
' Hilfsspalte mit letzten 2 Stellen
Columns(intSp + 1).Insert
If intUeb > 0 Then _
Range(Cells(1, intSp + 1), Cells(intUeb, intSp + 1)) = "Hilf"
Range(Cells(intUeb + 1, intSp + 1), _
Cells(lngLRow, intSp + 1)).FormulaR1C1Local = "=RECHTS(ZS(-1);2)"
' sortieren
Range(Rows(intUeb + 1), Rows(lngLRow)).Sort _
Key1:=Range("G3"), Order1:=xlAscending, _
Header:=xlNo, _
OrderCustom:=1, MatchCase:=False, Orientation:=xlTopToBottom, _
DataOption1:=xlSortNormal
Cells(intUeb + 1, intSp).Select
End Sub
' Ermittlung der Spaltennummer 1...256 aus der Spaltenbezeichnung A...IV
Function SpNumm(ByVal spt$) As Integer
Dim zw1%, zw2%
If Len(spt) < 1 Or Len(spt) > 2 Then
SpNumm = CVErr(xlErrValue)
Else ' 1. Zeichen
zw1 = Asc(UCase(spt)) - 64
If zw1 < 1 Or zw1 > 26 Then zw1 = 999
If Len(spt) = 2 Then ' 2. Zeichen, falls vorhanden
zw1 = 26 * zw1
zw2 = Asc(UCase(Right(spt, 1))) - 64
If zw2 < 1 Or zw2 > 26 Then zw2 = 999
End If
zw1 = zw1 + zw2 ' Summe
If zw1 < 1 Or zw1 > 256 Then
SpNumm = CVErr(xlErrValue)
Else
SpNumm = zw1
End If
End If
End Function
Rückmeldung wäre nett! - Grüße von Erich aus Kamp-Lintfort