Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Sub ZUTEIL_()
- Application.ScreenUpdating = False
- Dim t As Single
- t = Timer
- Dim answer As VbMsgBoxResult
- answer = MsgBox("Do you want to run ZUTEIL_ macro?", vbYesNo, "Run Macro")
- If answer = vbYes Then
- Dim WS_Count As Integer
- Dim i As Integer
- Dim last_record As Integer
- Dim art_num As String
- Dim art_count As Integer
- Dim active_rows As Integer
- ActiveWorkbook.Sheets.Add After:=Sheets(Sheets.Count)
- WS_Count = ActiveWorkbook.Worksheets.Count
- Range("a1").Value = "Artnr"
- Range("b1").Value = "LiefNr"
- Range("c1").Value = "von_datum"
- Range("d1").Value = "bis_datum"
- Range("e1").Value = "Filiale"
- Range("f1").Value = "Zuteilmenge"
- Range("g1").Value = "Ve_Be_Faktor"
- Range("h1").Value = "Send_Cd"
- Range("i1").Value = "Aufteil_Cd"
- For i = 1 To WS_Count - 1
- ActiveWorkbook.Worksheets(i).Select
- If Range("A2") = "" Then
- Range("b2:p2").Select
- Selection.AutoFilter
- ActiveSheet.Range(Selection, Selection.End(xlDown)).AutoFilter Field:=5, Criteria1:="<>TOTAL"
- ActiveSheet.Range(Selection, Selection.End(xlDown)).AutoFilter Field:=14, Criteria1:=">0"
- Range("B3").Select
- Range(Selection, Selection.End(xlDown)).Select
- Application.CutCopyMode = False
- Selection.Copy
- ActiveWorkbook.Worksheets(WS_Count).Select
- If Range("A2") = "" Then
- Range("A2").Select
- Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
- :=False, Transpose:=False
- ElseIf Range("A3") = "" Then
- Range("A3").Select
- Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
- :=False, Transpose:=False
- Else
- last_record = Range("A2").End(xlDown).Row + 1
- Cells(last_record, 1).Select
- Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
- :=False, Transpose:=False
- End If
- ActiveWorkbook.Worksheets(i).Select
- Range("D3").Select
- Range(Selection, Selection.End(xlDown)).Select
- Application.CutCopyMode = False
- Selection.Copy
- ActiveWorkbook.Worksheets(WS_Count).Select
- If Range("E2") = "" Then
- Range("E2").Select
- Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
- :=False, Transpose:=False
- ElseIf Range("E3") = "" Then
- Range("E3").Select
- Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
- :=False, Transpose:=False
- Else
- last_record = Range("E2").End(xlDown).Row + 1
- Cells(last_record, 5).Select
- Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
- :=False, Transpose:=False
- End If
- ActiveWorkbook.Worksheets(i).Select
- Range("O3").Select
- Range(Selection, Selection.End(xlDown)).Select
- Application.CutCopyMode = False
- Selection.Copy
- ActiveWorkbook.Worksheets(WS_Count).Select
- If Range("F2") = "" Then
- Range("F2").Select
- Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
- :=False, Transpose:=False
- ElseIf Range("F3") = "" Then
- Range("F3").Select
- Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
- :=False, Transpose:=False
- Else
- last_record = Range("F2").End(xlDown).Row + 1
- Cells(last_record, 6).Select
- Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
- :=False, Transpose:=False
- End If
- Else
- Dim cur_cols As Integer
- cur_cols = Range("a5").End(xlToRight).Column
- Range(Cells(7, 1), Cells(7, cur_cols)).Select
- Selection.AutoFilter
- ActiveSheet.Range(Selection, Selection.End(xlDown)).AutoFilter Field:=cur_cols, Criteria1:=">0"
- art_num = ActiveWorkbook.Worksheets(i).Name
- If WorksheetFunction.CountIf(Range(Cells(8, cur_cols), Cells(250, cur_cols)), ">0") > 1 Then
- Range("a8").Select
- art_count = Application.WorksheetFunction.Subtotal(3, Range(Selection, Selection.End(xlDown)))
- ActiveWorkbook.Worksheets(WS_Count).Select
- If Range("A2") = "" Then
- Range("A2", Cells(art_count + 1, 1)).Value = art_num
- ElseIf Range("A3") = "" Then
- Range("A3", Cells(art_count + 1, 1)).Value = art_num
- Else
- last_record = Range("A2").End(xlDown).Row + 1
- Range(Cells(last_record, 1), Cells(last_record + art_count - 1, 1)).Value = art_num
- End If
- ActiveWorkbook.Worksheets(i).Select
- Range("A8").Select
- Range(Selection, Selection.End(xlDown)).Select
- Application.CutCopyMode = False
- Selection.Copy
- ActiveWorkbook.Worksheets(WS_Count).Select
- If Range("E2") = "" Then
- Range("E2").Select
- Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
- :=False, Transpose:=False
- ElseIf Range("E3") = "" Then
- Range("E3").Select
- Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
- :=False, Transpose:=False
- Else
- last_record = Range("E2").End(xlDown).Row + 1
- Cells(last_record, 5).Select
- Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
- :=False, Transpose:=False
- End If
- ActiveWorkbook.Worksheets(i).Select
- Cells(8, cur_cols).Select
- Range(Selection, Selection.End(xlDown)).Select
- Application.CutCopyMode = False
- Selection.Copy
- ActiveWorkbook.Worksheets(WS_Count).Select
- If Range("F2") = "" Then
- Range("F2").Select
- Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
- :=False, Transpose:=False
- ElseIf Range("F3") = "" Then
- Range("F3").Select
- Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
- :=False, Transpose:=False
- Else
- last_record = Range("F2").End(xlDown).Row + 1
- Cells(last_record, 6).Select
- Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
- :=False, Transpose:=False
- End If
- ElseIf WorksheetFunction.CountIf(Range(Cells(8, cur_cols), Cells(250, cur_cols)), ">0") = 1 Then
- art_count = 1
- ActiveWorkbook.Worksheets(WS_Count).Select
- If Range("A2") = "" Then
- Range("A2", Cells(art_count + 1, 1)).Value = art_num
- ElseIf Range("A3") = "" Then
- Range("A3", Cells(art_count + 1, 1)).Value = art_num
- Else
- last_record = Range("A2").End(xlDown).Row + 1
- Range(Cells(last_record, 1), Cells(last_record + art_count - 1, 1)).Value = art_num
- End If
- ActiveWorkbook.Worksheets(i).Select
- Range("A8").Select
- Selection.Copy
- ActiveWorkbook.Worksheets(WS_Count).Select
- If Range("E2") = "" Then
- Range("E2").Select
- Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
- :=False, Transpose:=False
- ElseIf Range("E3") = "" Then
- Range("E3").Select
- Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
- :=False, Transpose:=False
- Else
- last_record = Range("E2").End(xlDown).Row + 1
- Cells(last_record, 5).Select
- Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
- :=False, Transpose:=False
- End If
- ActiveWorkbook.Worksheets(i).Select
- Cells(8, cur_cols).Select
- Selection.Copy
- ActiveWorkbook.Worksheets(WS_Count).Select
- If Range("F2") = "" Then
- Range("F2").Select
- Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
- :=False, Transpose:=False
- ElseIf Range("F3") = "" Then
- Range("F3").Select
- Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
- :=False, Transpose:=False
- Else
- last_record = Range("F2").End(xlDown).Row + 1
- Cells(last_record, 6).Select
- Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
- :=False, Transpose:=False
- End If
- End If
- End If
- Next i
- Range("A2").Select
- active_rows = Range(Selection, Selection.End(xlDown)).Count
- Range("B2", Cells(active_rows + 1, 2)).Value = 699998
- Range("H2", Cells(active_rows + 1, 8)).Value = "J"
- Range("I2", Cells(active_rows + 1, 9)).Value = "K"
- Range("A2:I2").Select
- Range(Selection, Selection.End(xlDown)).Select
- Selection.Copy
- End If
- MsgBox "The task is completed in " & Round(Timer - t, 0) & "s"
- End Sub
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement