Live-Forum - Die aktuellen Beiträge
Datum
Titel
17.10.2025 10:28:49
16.10.2025 17:40:39
Anzeige
Anzeige
HERBERS
Excel-Forum (Archiv)
20+ Jahre Excel-Kompetenz: Von Anwendern, für Anwender

Forumthread: Formatierung (Dropdown) soll übertragen werden

Formatierung (Dropdown) soll übertragen werden
30.05.2018 12:10:23
Zep
Hallo ich habe folgende Programmierung und ich möchte, dass bei der Erstellung der neuen Sheets die ursprüngliche Formatierung beibehalten wird, sprich Dropdowns.
Wie mache ich das?
Sub KritToSheet ()
Dim objShSource As Worksheet, objSh As Worksheet
Dim rng As Range, rngCopy As Range
Dim varTemp As Variant
Dim strFind As String, strFirst As String
Dim lngLast As Long, lngAct As Long
On Error GoTo ErrExit
With Application
.ScreenUpdating = False
.EnableEvents = False
.DisplayAlerts = False
.Calculation = xlCalculationManual
.Cursor = xlWait
End With
Set objShSource = Sheets("Tabelle1") 'Quelltabelle - anpassen
With objShSource
lngLast = .Cells(Rows.Count, 24).End(xlUp).Row
lngAct = lngLast
varTemp = .Range("A2:IV" & lngLast)
Do While lngAct > 1
strFind = .Cells(2, 24)
Set rng = .Range("X2:X" & lngAct).Find(what:=strFind, lookat:=xlWhole)
If Not rng Is Nothing Then
strFirst = rng.Address
Do
If rngCopy Is Nothing Then
Set rngCopy = .Rows(rng.Row)
Else
Set rngCopy = Union(rngCopy, .Rows(rng.Row))
End If
Set rng = .Range("X2:X" & lngAct).FindNext(rng)
Loop While Not rng Is Nothing And strFirst  rng.Address
End If
If Not rngCopy Is Nothing Then
Set objSh = Worksheets.Add(after:=Sheets(Sheets.Count))
On Error Resume Next
objSh.Name = strFind
If Err.Number  0 Then
objSh.Name = strFind & Format(Now, "hhmmss")
Err.Clear
End If
On Error GoTo ErrExit
rngCopy.Copy objSh.Cells(2, 1)
objShSource.Rows(1).Copy objSh.Rows(1)
rngCopy.Delete
Set rngCopy = Nothing
Set objSh = Nothing
End If
lngAct = .Cells(Rows.Count, 24).End(xlUp).Row
Loop
.Range("A2:IV" & lngLast) = varTemp
End With
ErrExit:
Set objShSource = Nothing
With Application
.ScreenUpdating = True
.EnableEvents = True
.DisplayAlerts = True
.Calculation = xlCalculationAutomatic
.Cursor = xlDefault
End With
End Sub

Anzeige

1
Beitrag zum Forumthread
Beitrag zu diesem Forumthread

Betreff
Datum
Anwender
Anzeige
AW: Formatierung (Dropdown) soll übertragen werden
03.06.2018 00:04:56
fcs
Hallo Zep,
damit die Formatierungen, DropDowns, etc in der Quell-Tabelle erhalten bleiben darf man die jeweils gefundenen Zeilen nicht komplett löschen sondern nur ihre Inhalte.
Dazu muss man dann auch den jeweils zu suchenden Wert etwas anders ermitteln.
Alternativ kann man auch zuerst die in Spalte X vorkommenden Werte ermitteln und dann diese abarbeiten. Dann müssen die Zellen in der Quelle garnicht erst gelöscht werden.
Gruß
Franz
Sub KritToSheet()
Dim objShSource As Worksheet, objSh As Worksheet
Dim rng As Range, rngCopy As Range
Dim varTemp As Variant
Dim strFind As String, strFirst As String
Dim lngLast As Long, lngAct As Long
On Error GoTo ErrExit
With Application
.ScreenUpdating = False
.EnableEvents = False
.DisplayAlerts = False
.Calculation = xlCalculationManual
.Cursor = xlWait
End With
Set objShSource = Sheets("Tabelle1") 'Quelltabelle - anpassen
With objShSource
lngLast = .Cells(Rows.Count, 24).End(xlUp).Row
lngAct = 2                                                            '###
varTemp = .Range("A2:IV" & lngLast)
Do
strFind = .Cells(lngAct, 24)                                        '###
If strFind  "" Then                                               '###
Set rng = .Range("X2:X" & lngLast).Find(what:=strFind, lookat:=xlWhole) '###
If Not rng Is Nothing Then
strFirst = rng.Address
Do
If rngCopy Is Nothing Then
Set rngCopy = .Rows(rng.Row)
Else
Set rngCopy = Union(rngCopy, .Rows(rng.Row))
End If
Set rng = .Range("X2:X" & lngLast).FindNext(rng)        '###
Loop While Not rng Is Nothing And strFirst  rng.Address
End If
If Not rngCopy Is Nothing Then
Set objSh = Worksheets.Add(after:=Sheets(Sheets.Count))
On Error Resume Next
objSh.Name = strFind
If Err.Number  0 Then
objSh.Name = strFind & Format(Now, "hhmmss")
Err.Clear
End If
On Error GoTo ErrExit
rngCopy.Copy objSh.Cells(2, 1)
objShSource.Rows(1).Copy objSh.Rows(1)
rngCopy.ClearContents                                 '###
Set rngCopy = Nothing
Set objSh = Nothing
End If
End If                                                   '###
lngAct = lngAct + 1                                      '###
Loop Until lngAct > lngLast                                '###
.Range("A2:IV" & lngLast) = varTemp
End With
ErrExit:
Set objShSource = Nothing
With Application
.ScreenUpdating = True
.EnableEvents = True
.DisplayAlerts = True
.Calculation = xlCalculationAutomatic
.Cursor = xlDefault
End With
End Sub

Alternative:
Sub KritToSheet_Alternativ()
Dim objShSource As Worksheet, objSh As Worksheet
Dim rng As Range, rngCopy As Range
Dim colFind As New Collection
Dim strFind As String, strFirst As String
Dim lngLast As Long, lngZei As Long
On Error GoTo ErrExit
With Application
.ScreenUpdating = False
.EnableEvents = False
.DisplayAlerts = False
.Calculation = xlCalculationManual
.Cursor = xlWait
End With
Set objShSource = Sheets("Tabelle1") 'Quelltabelle - anpassen
With objShSource
lngLast = .Cells(Rows.Count, 24).End(xlUp).Row
'Werte in Spalte X ohne Doppelte in Collection sammeln
On Error Resume Next
For lngZei = 2 To lngLast
colFind.Add Item:=.Cells(lngZei, 24), Key:=.Cells(lngZei, 24).Text
Next
'Werte aus Spalte X in Collection abarbeiten
For lngZei = 1 To colFind.Count
strFind = colFind(lngZei)
Set rng = .Range("X2:X" & lngLast).Find(what:=strFind, lookat:=xlWhole)
If Not rng Is Nothing Then
strFirst = rng.Address
Do
If rngCopy Is Nothing Then
Set rngCopy = .Rows(rng.Row)
Else
Set rngCopy = Union(rngCopy, .Rows(rng.Row))
End If
Set rng = .Range("X2:X" & lngLast).FindNext(rng)
Loop While Not rng Is Nothing And strFirst  rng.Address
End If
If Not rngCopy Is Nothing Then
Set objSh = Worksheets.Add(after:=Sheets(Sheets.Count))
On Error Resume Next
objSh.Name = strFind
If Err.Number  0 Then
objSh.Name = strFind & Format(Now, "hhmmss")
Err.Clear
End If
On Error GoTo ErrExit
rngCopy.Copy objSh.Cells(2, 1)
objShSource.Rows(1).Copy objSh.Rows(1)
Set rngCopy = Nothing
Set objSh = Nothing
End If
Next lngZei
End With
ErrExit:
Set objShSource = Nothing
With Application
.ScreenUpdating = True
.EnableEvents = True
.DisplayAlerts = True
.Calculation = xlCalculationAutomatic
.Cursor = xlDefault
End With
End Sub

Anzeige
;

Forumthreads zu verwandten Themen

Entdecke relevante Threads

Schau dir verwandte Threads basierend auf dem aktuellen Thema an

Alle relevanten Threads mit Inhaltsvorschau entdecken
Anzeige
Anzeige

Infobox / Tutorial

Dropdown Formatierung in Excel Übertragen


Schritt-für-Schritt-Anleitung

Um die Dropdown-Formatierung in Excel zu übernehmen, kannst Du den folgenden VBA-Code verwenden. Dieser Code sorgt dafür, dass die Formatierungen bei der Erstellung neuer Tabellenblätter beibehalten werden:

Sub KritToSheet()
    Dim objShSource As Worksheet, objSh As Worksheet
    Dim rng As Range, rngCopy As Range
    Dim varTemp As Variant
    Dim strFind As String, strFirst As String
    Dim lngLast As Long, lngAct As Long
    On Error GoTo ErrExit
    With Application
        .ScreenUpdating = False
        .EnableEvents = False
        .DisplayAlerts = False
        .Calculation = xlCalculationManual
        .Cursor = xlWait
    End With
    Set objShSource = Sheets("Tabelle1") 'Quelltabelle - anpassen
    With objShSource
        lngLast = .Cells(Rows.Count, 24).End(xlUp).Row
        lngAct = 2
        varTemp = .Range("A2:IV" & lngLast)
        Do
            strFind = .Cells(lngAct, 24)
            If strFind <> "" Then
                Set rng = .Range("X2:X" & lngLast).Find(what:=strFind, lookat:=xlWhole)
                If Not rng Is Nothing Then
                    strFirst = rng.Address
                    Do
                        If rngCopy Is Nothing Then
                            Set rngCopy = .Rows(rng.Row)
                        Else
                            Set rngCopy = Union(rngCopy, .Rows(rng.Row))
                        End If
                        Set rng = .Range("X2:X" & lngLast).FindNext(rng)
                    Loop While Not rng Is Nothing And strFirst <> rng.Address
                End If
                If Not rngCopy Is Nothing Then
                    Set objSh = Worksheets.Add(after:=Sheets(Sheets.Count))
                    On Error Resume Next
                    objSh.Name = strFind
                    If Err.Number <> 0 Then
                        objSh.Name = strFind & Format(Now, "hhmmss")
                        Err.Clear
                    End If
                    On Error GoTo ErrExit
                    rngCopy.Copy objSh.Cells(2, 1)
                    objShSource.Rows(1).Copy objSh.Rows(1)
                    rngCopy.ClearContents
                    Set rngCopy = Nothing
                    Set objSh = Nothing
                End If
            End If
            lngAct = lngAct + 1
        Loop Until lngAct > lngLast
        .Range("A2:IV" & lngLast) = varTemp
    End With
ErrExit:
    Set objShSource = Nothing
    With Application
        .ScreenUpdating = True
        .EnableEvents = True
        .DisplayAlerts = True
        .Calculation = xlCalculationAutomatic
        .Cursor = xlDefault
    End With
End Sub

Häufige Fehler und Lösungen

  1. Fehler: Formatierung geht verloren

    • Stelle sicher, dass Du die Zellen nur von ihren Inhalten befreist und nicht die Zeilen löschst. Verwende ClearContents anstelle von Delete.
  2. Fehler: Dropdowns erscheinen nicht

    • Prüfe, ob die Dropdown-Listen korrekt in der Quelltabelle definiert sind. Manchmal müssen die Datenüberprüfungen manuell neu zugewiesen werden.

Alternative Methoden

Eine alternative Methode zur Übertragung der Dropdown-Formatierung könnte das Erstellen einer Collection sein, um doppelte Werte zu vermeiden. Hier ist ein Beispiel:

Sub KritToSheet_Alternativ()
    Dim objShSource As Worksheet, objSh As Worksheet
    Dim rng As Range, rngCopy As Range
    Dim colFind As New Collection
    Dim strFind As String, strFirst As String
    Dim lngLast As Long, lngZei As Long
    On Error GoTo ErrExit
    With Application
        .ScreenUpdating = False
        .EnableEvents = False
        .DisplayAlerts = False
        .Calculation = xlCalculationManual
        .Cursor = xlWait
    End With
    Set objShSource = Sheets("Tabelle1") 'Quelltabelle - anpassen
    With objShSource
        lngLast = .Cells(Rows.Count, 24).End(xlUp).Row
        For lngZei = 2 To lngLast
            colFind.Add Item:=.Cells(lngZei, 24), Key:=.Cells(lngZei, 24).Text
        Next
        For lngZei = 1 To colFind.Count
            strFind = colFind(lngZei)
            Set rng = .Range("X2:X" & lngLast).Find(what:=strFind, lookat:=xlWhole)
            If Not rng Is Nothing Then
                strFirst = rng.Address
                Do
                    If rngCopy Is Nothing Then
                        Set rngCopy = .Rows(rng.Row)
                    Else
                        Set rngCopy = Union(rngCopy, .Rows(rng.Row))
                    End If
                    Set rng = .Range("X2:X" & lngLast).FindNext(rng)
                Loop While Not rng Is Nothing And strFirst <> rng.Address
            End If
            If Not rngCopy Is Nothing Then
                Set objSh = Worksheets.Add(after:=Sheets(Sheets.Count))
                On Error Resume Next
                objSh.Name = strFind
                If Err.Number <> 0 Then
                    objSh.Name = strFind & Format(Now, "hhmmss")
                    Err.Clear
                End If
                On Error GoTo ErrExit
                rngCopy.Copy objSh.Cells(2, 1)
                objShSource.Rows(1).Copy objSh.Rows(1)
                Set rngCopy = Nothing
                Set objSh = Nothing
            End If
        Next lngZei
    End With
ErrExit:
    Set objShSource = Nothing
    With Application
        .ScreenUpdating = True
        .EnableEvents = True
        .DisplayAlerts = True
        .Calculation = xlCalculationAutomatic
        .Cursor = xlDefault
    End With
End Sub

Praktische Beispiele

  • Beispiel 1: Wenn Du eine Dropdown-Liste mit Werten in Spalte X hast, kannst Du die oben genannten Codes verwenden, um das Format zu übertragen. Achte darauf, die Quell-Tabelle korrekt zu benennen.

  • Beispiel 2: Nutze die Methode ClearContents, um sicherzustellen, dass die Formatierung beibehalten wird, während die Daten entfernt werden. Dies hilft insbesondere beim excel dropdown formatierung übernehmen.


Tipps für Profis

  • Dokumentation: Halte Deine VBA-Codes gut dokumentiert, um die Wartung zu erleichtern.
  • Testen: Teste Deine Codes in einer Kopie Deiner Datei, um versehentliche Datenverluste zu vermeiden.
  • Optimierung: Überprüfe den Code auf Performance-Optimierungen, besonders bei großen Datenmengen.

FAQ: Häufige Fragen

1. Wie kann ich die Dropdown-Formatierung in eine andere Excel-Datei übertragen?
Du kannst die Dropdown-Listen manuell kopieren oder den VBA-Code anpassen, um die Formatierungen in die neue Datei zu übertragen.

2. Funktioniert dieser Code in Excel 2016 und neueren Versionen?
Ja, der VBA-Code ist mit Excel 2016 und neueren Versionen kompatibel. Achte darauf, dass die Makros aktiviert sind.

Beliebteste Forumthreads (12 Monate)

Anzeige
Anzeige
Entdecke mehr
Finde genau, was du suchst

Die erweiterte Suchfunktion hilft dir, gezielt die besten Antworten zu finden

Suche nach den besten Antworten
Unsere beliebtesten Threads

Entdecke unsere meistgeklickten Beiträge in der Google Suche

Top 100 Threads jetzt ansehen
Anzeige