wie kann ich bitte per VBA die Zellinhalte (Spaltenbereich B:O) bis zur Spalte B nach links verschieben?
Es sollen nacher ab Spalte B gesehen, keine Lücken dazwischen sein.
Vorher:
Nachher:
Danke vorab!
Gruß,
Selma
Sub Prefix()
Dim WkSh As Worksheet
Dim lZeile As Long
Dim iText As Long, varEingabe
Set WkSh = ActiveSheet
varEingabe = Application.InputBox(Prompt:="Bitte Kürzel eingeben!" & vbLf & "LTA oder TST _
oder RNS", _
Title:="Prefix in Spalte A", Default:="LTA")
If varEingabe False Then
iText = varEingabe
For lZeile = 1 To WkSh.Cells(Rows.Count, 1).End(xlUp).Row
If WkSh.Cells(lZeile, 1).Value "" Then
WkSh.Cells(lZeile, 1).Value = "2014_" & iText & "_" & WkSh.Cells(lZeile, 1).Value
End If
Next lZeile
End If
End Sub
Option Explicit
Sub Prefix()
Dim lZeile&, varEingabe
varEingabe = InputBox("Bitte Kürzel eingeben!" & vbLf & "LTA oder TST oder RNS", "Prefix in _
Spalte A", "LTA")
If StrPtr(varEingabe) = 0 Then Exit Sub
If UCase(varEingabe) "LTA" And UCase(varEingabe) "TST" And UCase(varEingabe) "RNS" _
Then Exit Sub
If varEingabe vbNullString And Len(Trim(varEingabe)) > 0 Then
For lZeile = 1 To Cells(Rows.Count, 1).End(xlUp).Row
If Cells(lZeile, 1).Value "" Then
Cells(lZeile, 1).Value = "2014_" & UCase(varEingabe) & "_" & Cells(lZeile, 1).Value
End If
Next lZeile
End If
End Sub
Und es ist immernoch möglich den Code mehrfach auszuführen.A | |
1 | 2014_LTA_2014_LTA_A |
2 | 2014_LTA_2014_LTA_B |
3 | 2014_LTA_2014_LTA_C |
WkSh.Cells(lZeile, 1).Value = "2014_" & varEingabe & "_" & WkSh.Cells(lZeile, 1).Value
Sub Prefix()
Dim WkSh As Worksheet
Dim lZeile As Long
Dim iText As Long, varEingabe
Set WkSh = ActiveSheet
Eingabe:
varEingabe = Application.InputBox(Prompt:="Bitte Kürzel eingeben!" & vbLf _
& "LTA oder TST oder RNS", _
Title:="Prefix in Spalte A", Default:="LTA")
Select Case varEingabe
Case False
Case "LTA", "TST", "RNS"
For lZeile = 1 To WkSh.Cells(Rows.Count, 1).End(xlUp).Row
If WkSh.Cells(lZeile, 1).Value "" Then
WkSh.Cells(lZeile, 1).Value = "2014_" & varEingabe & "_" & WkSh.Cells(lZeile, 1). _
Value
End If
Next lZeile
Case Else
MsgBox "unzulässige Eingabe für Prefix in Spalte A"
GoTo Eingabe
End Select
End Sub