hier ohne Select Case
30.08.2011 10:37:41
Matthias
Hallo
Ich hoffe mir ist da kein Fehler unterlaufen.
Option Explicit
Public Frage$
Sub Claudia6()
Dim X&, col&, loletzte&, LastCol&
Frage$ = InputBox("Bitte Spaltenbuchstabe(n) für Kombination wählen", "Kombination wählen", "G" _
)
If StrPtr(Frage) = 0 Then Exit Sub 'Abbruch angeklickt
If IsNumeric(Frage) Then Exit Sub 'Eingabe als Text (Spaltenbuchstaben) erzwingen
On Error GoTo Fehler
col = Cells(1, Frage).Column
'Zeile(der letzte Zelle) der ausgewählten Spalte wählen
LastCol = Cells(Rows.Count, col).End(xlUp).Row
'MsgBox "Spalte " & col & " wurde gewählt"
If MsgBox("Kopiere Spalte: " & UCase(Frage) & vbLf & "inkl. KundenNr.: aus Spalte ""A"" ?", _
vbYesNo) = vbYes Then
For X = 2 To LastCol
loletzte = Cells(Rows.Count, 1).End(xlUp).Row + 1
If Cells(X, 1) "" And Cells(X, col) "" Then
Cells(loletzte, 1) = Cells(X, 1) & Cells(X, col) 'SpalteA + Auswahlspalte
End If
Next
Else
For X = 2 To LastCol
loletzte = Cells(Rows.Count, 1).End(xlUp).Row + 1
If Cells(X, 1) "" And Cells(X, col) "" Then
Cells(loletzte, 1) = Cells(X, col) 'nur Auswahlspalte
End If
Next
End If
Exit Sub
Fehler:
MsgBox "Bitte nur gültige Spaltenbuchstaben eingeben !" & vbLf & "[ " & UCase(Frage) & " ] _
ist als Spalte nicht vorhanden", vbInformation, " Fehler"
End Sub
Das Beispiel:
https://www.herber.de/bbs/user/76392.xls
Gruß Matthias