Live-Forum - Die aktuellen Beiträge
Anzeige
Archiv - Navigation
1624to1628
Aktuelles Verzeichnis
Verzeichnis Index
Übersicht Verzeichnisse
Vorheriger Thread
Rückwärts Blättern
Nächster Thread
Vorwärts blättern
Anzeige
HERBERS
Excel-Forum (Archiv)
20+ Jahre Excel-Kompetenz: Von Anwendern, für Anwender
Inhaltsverzeichnis

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

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

Beliebteste Forumthreads (12 Monate)

Anzeige

Beliebteste Forumthreads (12 Monate)

Anzeige
Anzeige
Anzeige