Advertisement
Tke439

Untitled

May 14th, 2020
1,284
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. Sub Sums()
  2. Application.ScreenUpdating = False
  3. Dim Mstr_Bk As Workbook, Mstr_Sht As Worksheet, Class_Sht As Worksheet, Class_Rng As Range, _
  4.    V_Sht As Worksheet, NV_Sht As Worksheet, Class_Sht_LR As Long, Mstr_Str_Num, V_Barcode, _
  5.    Mstr_Mvmt As Long, V_Mvmt As Long, NV_Barcode, NV_Mvmt As Long, mPath As String
  6.  
  7. Set Mstr_Bk = ActiveWorkbook
  8. Set Mstr_Sht = Mstr_Bk.Worksheets("Master")
  9. Set Class_Sht = Workbooks("Import Prep V1.1.xlsm").Worksheets("Classifications")
  10. Class_Sht.Cells.AutoFilter
  11. Set Class_Rng = Class_Sht.Range(Class_Sht.Cells(1, 1), Class_Sht.Cells(Class_Sht.Cells(Rows.Count, 1).End(xlUp).Row, 2))
  12. mPath = Application.Mstr_Bk.Path
  13.  
  14. With Mstr_Bk
  15.    Mstr_Sht.Copy After:=Sheets(Sheets.Count)
  16.    ActiveSheet.Name = "Value"
  17.    Set V_Sht = .Worksheets("Value")
  18.    Mstr_Sht.Copy After:=Sheets(Sheets.Count)
  19.    ActiveSheet.Name = "Non Value"
  20.    Set NV_Sht = .Worksheets("Non Value")
  21. End With
  22.  
  23. With V_Sht
  24.    With .Cells(4, 3).CurrentRegion
  25.       .RemoveDuplicates Columns:=3
  26.    End With
  27.    .Columns(8).ClearContents
  28.    .Range("H3").Value = "Reg_Movement"
  29.    For r = V_Sht.Cells(Rows.Count, 3).End(xlUp).Row To 4 Step -1
  30.       Set V_Barcode = .Cells(r, 3)
  31.       For t = Mstr_Sht.Cells(Rows.Count, 3).End(xlUp).Row To 4 Step -1
  32.          Mstr_Str_Num = Mstr_Sht.Cells(t, 1).Value
  33.          Mstr_Mvmt = Mstr_Sht.Cells(t, "H").Value
  34.          V_Mvmt = V_Sht.Cells(r, "H").Value
  35.          If Mstr_Mvmt = 0 Then
  36.          Else
  37.             If V_Barcode.Value <> Mstr_Sht.Cells(t, 3).Value Then
  38.             Else
  39.                If WorksheetFunction.VLookup(Mstr_Str_Num, Class_Rng, 2, False) = "V" Then
  40.                   .Cells(r, "H").Value = Mstr_Mvmt + V_Mvmt
  41.                Else
  42.                End If
  43.             End If
  44.          End If
  45.       Next t
  46.    Next r
  47.    .Columns(1).Delete
  48.    .Rows(2).Delete
  49.    .Rows(1).Delete
  50.    .Copy
  51.    ActiveSheet.Name = "Product"
  52.    Application.ActiveWorkbook.SaveAs Filename:=mPath & "\" & "Value Group" & ".xlsx"
  53.    Application.ActiveWorkbook.Close False
  54. End With
  55.  
  56. With NV_Sht
  57.    With .Cells(4, 3).CurrentRegion
  58.       .RemoveDuplicates Columns:=3
  59.    End With
  60.    .Columns(8).ClearContents
  61.    .Range("H3").Value = "Reg_Movement"
  62.    For r = NV_Sht.Cells(Rows.Count, 3).End(xlUp).Row To 4 Step -1
  63.       Set NV_Barcode = .Cells(r, 3)
  64.       For t = Mstr_Sht.Cells(Rows.Count, 3).End(xlUp).Row To 4 Step -1
  65.          Mstr_Str_Num = Mstr_Sht.Cells(t, 1).Value
  66.          Mstr_Mvmt = Mstr_Sht.Cells(t, "H").Value
  67.          NV_Mvmt = V_Sht.Cells(r, "H").Value
  68.          If Mstr_Mvmt = 0 Then
  69.          Else
  70.             If NV_Barcode.Value <> Mstr_Sht.Cells(t, 3).Value Then
  71.             Else
  72.                If WorksheetFunction.VLookup(Mstr_Str_Num, Class_Rng, 2, False) = "V" Then
  73.                   .Cells(r, "H").Value = Mstr_Mvmt + NV_Mvmt
  74.                Else
  75.                End If
  76.             End If
  77.          End If
  78.       Next t
  79.    Next r
  80.    .Columns(1).Delete
  81.    .Rows(2).Delete
  82.    .Rows(1).Delete
  83.    .Copy
  84.    ActiveSheet.Name = "Product"
  85.    Application.ActiveWorkbook.SaveAs Filename:=mPath & "\" & "Non Value Group" & ".xlsx"
  86.    Application.ActiveWorkbook.Close False
  87. End With
  88.  
  89. Application.ScreenUpdating = True
  90.  
  91. End Sub
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement