Option Base 1
Option Explicit
Sub DatenSortiertKopieren()
Call EventsOff
Dim Lzeile As Long, Qzeile As Long, Zaehler1 As Long
Dim WksName As String
Worksheets("Daten").Activate
Lzeile = Worksheets("Daten").Cells(Rows.Count, 1).End(xlUp).Row
ReDim ArrQ(Lzeile, 1) As Variant
ArrQ() = Range("A1:A" & Lzeile)
For Zaehler1 = 2 To Lzeile
If ArrQ(Zaehler1, 1) = "Schmieranweisung" Then
WksName = "Schmierung"
Zaehler1 = Zaehler1 + 2
End If
If ArrQ(Zaehler1, 1) = "Wartungsanweisung" Then
WksName = "Wartung"
Zaehler1 = Zaehler1 + 2
End If
If Mid(ArrQ(Zaehler1, 1), 1, 7) = "Legende" Or Mid(ArrQ(Zaehler1, 1), 1, 9) = "Bemerkung" Then WksName = ""
If WksName = "Schmierung" And ArrQ(Zaehler1, 1) <> "" Or WksName = "Wartung" And ArrQ(Zaehler1, 1) <> "" Then
Qzeile = Worksheets(WksName).Cells(Rows.Count, 1).End(xlUp).Row + 1
Worksheets("Daten").Rows(Zaehler1 & ":" & Zaehler1).Copy Worksheets(WksName).Cells(Qzeile, 1)
End If
Next Zaehler1
Call EventsOn
End SubPublic Sub EventsOff()
With Application
.ScreenUpdating = False
.EnableEvents = False
.Calculation = xlCalculationManual
End With
End SubPublic Sub EventsOn()
With Application
.ScreenUpdating = True
.EnableEvents = True
.Calculation = xlCalculationAutomatic
End With
End SubOption Base 1
Option Explicit
Sub DatenSortiertKopieren()
Call EventsOff
Dim Zaehler1 As Long, Zaehler2 As Long, Zeile1 As Long, Zeile2 As Long
Dim WksName As String, Text1 As String, Text2 As String
Worksheets("Daten").Activate
ReDim ArrQ(Worksheets("Daten").Cells(Rows.Count, 1).End(xlUp).Row, 2) As Variant
ArrQ() = Range("A1:B" & Worksheets("Daten").Cells(Rows.Count, 1).End(xlUp).Row)
For Zaehler1 = 2 To UBound(ArrQ())
If UCase(ArrQ(Zaehler1, 1)) = "SCHMIERANWEISUNG" Then
WksName = "Schmierung"
Zaehler1 = Zaehler1 + 2
Zeile1 = Zaehler1
End If
If UCase(ArrQ(Zaehler1, 1)) = "WARTUNGSANWEISUNG" Then
WksName = "Wartung"
Zaehler1 = Zaehler1 + 2
Zeile1 = Zaehler1
End If
If UCase(Mid(ArrQ(Zaehler1, 1), 1, 7)) = "LEGENDE" Or UCase(Mid(ArrQ(Zaehler1, 1), 1, 9)) = "BEMERKUNG" Then
Zeile2 = Zaehler1 - 2
Worksheets("Daten").Rows(Zeile1 & ":" & Zeile2).Copy _
Worksheets(WksName).Cells(Worksheets(WksName).Cells(Rows.Count, 2).End(xlUp).Row + 1, 1)
WksName = ""
End If
Next Zaehler1
Worksheets("Schmierung").Activate
ArrQ() = Range("A1:A" & Worksheets("Schmierung").Cells(Rows.Count, 2).End(xlUp).Row)
For Zaehler1 = 2 To UBound(ArrQ())
If ArrQ(Zaehler1, 1) <> "" And ArrQ(Zaehler1, 1) <> Text1 Then
Text1 = ArrQ(Zaehler1, 1)
Zaehler2 = 2
End If
If ArrQ(Zaehler1, 1) = "" Then
If Len(CStr(Zaehler2)) = 1 Then Text2 = Mid(Text1, 1, Len(Text1) - 3) & "00" & CStr(Zaehler2)
If Len(CStr(Zaehler2)) = 2 Then Text2 = Mid(Text1, 1, Len(Text1) - 3) & "0" & CStr(Zaehler2)
Zaehler2 = Zaehler2 + 1
ArrQ(Zaehler1, 1) = Text2
End If
Next Zaehler1
Range("A1:A" & Worksheets("Schmierung").Cells(Rows.Count, 2).End(xlUp).Row) = ArrQ()
Worksheets("Wartung").Activate
ArrQ() = Range("A1:A" & Worksheets("Wartung").Cells(Rows.Count, 2).End(xlUp).Row)
For Zaehler1 = 2 To UBound(ArrQ())
If ArrQ(Zaehler1, 1) <> "" And ArrQ(Zaehler1, 1) <> Text1 Then
Text1 = ArrQ(Zaehler1, 1)
Zaehler2 = 2
End If
If ArrQ(Zaehler1, 1) = "" Then
If Len(CStr(Zaehler2)) = 1 Then Text2 = Mid(Text1, 1, Len(Text1) - 3) & "00" & CStr(Zaehler2)
If Len(CStr(Zaehler2)) = 2 Then Text2 = Mid(Text1, 1, Len(Text1) - 3) & "0" & CStr(Zaehler2)
Zaehler2 = Zaehler2 + 1
ArrQ(Zaehler1, 1) = Text2
End If
Next Zaehler1
Range("A1:A" & Worksheets("Wartung").Cells(Rows.Count, 2).End(xlUp).Row) = ArrQ()
Call EventsOn
End SubPublic Sub EventsOff()
With Application
.ScreenUpdating = False
.EnableEvents = False
.Calculation = xlCalculationManual
End With
End SubPublic Sub EventsOn()
With Application
.ScreenUpdating = True
.EnableEvents = True
.Calculation = xlCalculationAutomatic
End With
End Sub
VBA Find-Methode
ignaz 27.11.2007 - 204 Hits - 3 Antworten
VBA: cells.find für verbundene Zellen
Oli00 12.12.2007 - 155 Hits - 2 Antworten
Cells.Find - Variable funktioniert nicht
derlistigelurch 17.01.2008 - 16 Hits - 3 Antworten
VBA
gropi 23.04.2008 - 50 Hits - 1 Antwort
VBA
Benjo_pont 03.07.2008 - 130 Hits - 2 Antworten