Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Sub Sums()
- Application.ScreenUpdating = False
- Dim Mstr_Bk As Workbook, Mstr_Sht As Worksheet, Class_Sht As Worksheet, Class_Rng As Range, _
- V_Sht As Worksheet, NV_Sht As Worksheet, Class_Sht_LR As Long, Mstr_Str_Num, V_Barcode, _
- Mstr_Mvmt As Long, V_Mvmt As Long, NV_Barcode, NV_Mvmt As Long, mPath As String
- Set Mstr_Bk = ActiveWorkbook
- Set Mstr_Sht = Mstr_Bk.Worksheets("Master")
- Set Class_Sht = Workbooks("Import Prep V1.1.xlsm").Worksheets("Classifications")
- Class_Sht.Cells.AutoFilter
- Set Class_Rng = Class_Sht.Range(Class_Sht.Cells(1, 1), Class_Sht.Cells(Class_Sht.Cells(Rows.Count, 1).End(xlUp).Row, 2))
- mPath = Application.Mstr_Bk.Path
- With Mstr_Bk
- Mstr_Sht.Copy After:=Sheets(Sheets.Count)
- ActiveSheet.Name = "Value"
- Set V_Sht = .Worksheets("Value")
- Mstr_Sht.Copy After:=Sheets(Sheets.Count)
- ActiveSheet.Name = "Non Value"
- Set NV_Sht = .Worksheets("Non Value")
- End With
- With V_Sht
- With .Cells(4, 3).CurrentRegion
- .RemoveDuplicates Columns:=3
- End With
- .Columns(8).ClearContents
- .Range("H3").Value = "Reg_Movement"
- For r = V_Sht.Cells(Rows.Count, 3).End(xlUp).Row To 4 Step -1
- Set V_Barcode = .Cells(r, 3)
- For t = Mstr_Sht.Cells(Rows.Count, 3).End(xlUp).Row To 4 Step -1
- Mstr_Str_Num = Mstr_Sht.Cells(t, 1).Value
- Mstr_Mvmt = Mstr_Sht.Cells(t, "H").Value
- V_Mvmt = V_Sht.Cells(r, "H").Value
- If Mstr_Mvmt = 0 Then
- Else
- If V_Barcode.Value <> Mstr_Sht.Cells(t, 3).Value Then
- Else
- If WorksheetFunction.VLookup(Mstr_Str_Num, Class_Rng, 2, False) = "V" Then
- .Cells(r, "H").Value = Mstr_Mvmt + V_Mvmt
- Else
- End If
- End If
- End If
- Next t
- Next r
- .Columns(1).Delete
- .Rows(2).Delete
- .Rows(1).Delete
- .Copy
- ActiveSheet.Name = "Product"
- Application.ActiveWorkbook.SaveAs Filename:=mPath & "\" & "Value Group" & ".xlsx"
- Application.ActiveWorkbook.Close False
- End With
- With NV_Sht
- With .Cells(4, 3).CurrentRegion
- .RemoveDuplicates Columns:=3
- End With
- .Columns(8).ClearContents
- .Range("H3").Value = "Reg_Movement"
- For r = NV_Sht.Cells(Rows.Count, 3).End(xlUp).Row To 4 Step -1
- Set NV_Barcode = .Cells(r, 3)
- For t = Mstr_Sht.Cells(Rows.Count, 3).End(xlUp).Row To 4 Step -1
- Mstr_Str_Num = Mstr_Sht.Cells(t, 1).Value
- Mstr_Mvmt = Mstr_Sht.Cells(t, "H").Value
- NV_Mvmt = V_Sht.Cells(r, "H").Value
- If Mstr_Mvmt = 0 Then
- Else
- If NV_Barcode.Value <> Mstr_Sht.Cells(t, 3).Value Then
- Else
- If WorksheetFunction.VLookup(Mstr_Str_Num, Class_Rng, 2, False) = "V" Then
- .Cells(r, "H").Value = Mstr_Mvmt + NV_Mvmt
- Else
- End If
- End If
- End If
- Next t
- Next r
- .Columns(1).Delete
- .Rows(2).Delete
- .Rows(1).Delete
- .Copy
- ActiveSheet.Name = "Product"
- Application.ActiveWorkbook.SaveAs Filename:=mPath & "\" & "Non Value Group" & ".xlsx"
- Application.ActiveWorkbook.Close False
- End With
- Application.ScreenUpdating = True
- End Sub
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement