Advertisement
Guest User

Untitled

a guest
Feb 15th, 2019
140
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1.  
  2.  
  3. Sub WAFCO_Tracking_Cleanup()
  4. Application.ScreenUpdating = False
  5. Application.Calculation = xlCalculationManual
  6. Dim rowcount As Integer
  7. Dim MainWS As Worksheet, CarrierWS As Worksheet
  8. Dim RW As Range
  9. Dim Carrier As String
  10. Set MainWS = Sheets("Sheet1")
  11.  
  12. Range("R:R").EntireColumn.Delete
  13. Range("O:O").EntireColumn.Delete
  14. Range("J:K").EntireColumn.Delete
  15. Range("A:F").EntireColumn.Delete
  16.  
  17.  
  18.  
  19.  
  20. Range("B1").Value = "PRO#"
  21. Range("C1").Value = "BOL#"
  22. Range("D1").Value = "Status"
  23. Range("E1").Value = "Ship Date"
  24.  
  25. Range("F1").Value = "Dely Date"
  26. Range("G1").Value = "Origin"
  27. Range("H1").Value = "Destination"
  28.  
  29.  
  30. rowcount = MainWS.UsedRange.Rows.Count
  31.  
  32.  
  33. For i = 2 To rowcount
  34.         If Cells(i, 4).Value = "Shipment Delivered" Then
  35.         Rows(i).Delete
  36.        
  37.         End If
  38.    
  39.     Next
  40.    
  41.     MainWS.Sort.SortFields.Clear
  42.     MainWS.Sort.SortFields.Add2 Key:=Range("A2:A" & rowcount), SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:=xlSortNormal
  43.     MainWS.Sort.SortFields.Add2 Key:=Range("E2:E" & rowcount), SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:=xlSortNormal
  44.     With MainWS.Sort
  45.         .SetRange Range("A1:H" & rowcount)
  46.         .Header = xlYes
  47.         .MatchCase = False
  48.         .Orientation = xlTopToBottom
  49.         .SortMethod = xlPinYin
  50.         .Apply
  51.     End With
  52.  
  53.  
  54. MainWS.Columns("A:Z").AutoFit
  55.  
  56. Const CarCol = 1, AddrCol = 2, CityCol = 3, StateCol = 4, ZipCol = 5, DateCol = 6
  57.  
  58.  
  59.    
  60.     For Each RW In MainWS.UsedRange.Rows
  61.         Set CarrierWS = Nothing
  62.         If RW.Row > 1 Then     ' don't do the header row
  63.            Carrier = RW.Columns(CarCol).Value
  64.  
  65.             On Error Resume Next
  66.                 Set CarrierWS = Sheets(Carrier)
  67.             On Error GoTo 0
  68.  
  69.             If CarrierWS Is Nothing Then  ' the WS does not exist
  70.                Sheets.Add    ' this will change the active sheet
  71.                Set CarrierWS = ActiveSheet
  72.                 CarrierWS.Name = Carrier
  73.                 MainWS.UsedRange.Rows(1).Copy  ' i am assuming you have a header row
  74.                CarrierWS.Paste              ' that you want to copy to the new sheet
  75.                CarrierWS.Range("A1:H1").Interior.ColorIndex = 37
  76. TheWall
  77.  
  78.             Else
  79.                 CarrierWS.Activate
  80.             End If  ' sheet not exist
  81.  
  82.             CarrierWS.Cells(ActiveSheet.UsedRange.Rows.Count + 1, 1).Activate   ' go to the first empty row
  83.            RW.Copy   ' copy the row from the main sheet
  84.            CarrierWS.Paste
  85. TheWall
  86.  
  87.         End If  ' header row
  88.    Next RW
  89.  
  90.     For Each CarrierWS In Sheets
  91.         If CarrierWS.Name <> MainWS.Name Then   ' Don't sort the main sheet
  92.            CarrierWS.Sort.SortFields.Clear
  93.             CarrierWS.Sort.SortFields.Add2 Key:=CarrierWS.Columns(DateCol), SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:=xlSortNormal
  94.             With CarrierWS.Sort
  95.                 .SetRange CarrierWS.UsedRange
  96.                 .Header = xlYes
  97.                 .MatchCase = False
  98.                 .Orientation = xlTopToBottom
  99.                 .SortMethod = xlPinYin
  100.                 .Apply
  101.             End With
  102. CarrierWS.Columns("A:Z").AutoFit
  103.  
  104.         End If
  105.         Dim iCntr, sht
  106.  
  107. 'This will hold the colorIndex number
  108. iCntr = 2
  109.  
  110. 'looping throgh the all the sheets of the workbook
  111. For Each sht In ActiveWorkbook.Worksheets
  112.     iCntr = iCntr + 1
  113.    
  114.     'Applying the colors to Sheet tabs
  115.    sht.Tab.ColorIndex = iCntr
  116. Next
  117.     Next CarrierWS
  118.  
  119.  
  120.  
  121.  
  122. Application.ScreenUpdating = True
  123. Application.Calculation = xlCalculationAutomatic
  124.  
  125.  
  126. End Sub
  127.  
  128.  
  129.  
  130. Sub TheWall()
  131.  
  132. Application.ScreenUpdating = False
  133. Dim lngLstCol As Long, lngLstRow As Long
  134.  
  135. lngLstRow = ActiveSheet.UsedRange.Rows.Count
  136. lngLstCol = ActiveSheet.UsedRange.Columns.Count
  137.  
  138. For Each rngCell In Range("A2:A" & lngLstRow)
  139.     If rngCell.Value > "" Then
  140.         r = rngCell.Row
  141.         c = rngCell.Column
  142.         Range(Cells(r, c), Cells(r, lngLstCol)).Select
  143.             With Selection.Borders
  144.                 .LineStyle = xlContinuous
  145.                 .Weight = xlThin
  146.                 .ColorIndex = xlAutomatic
  147.             End With
  148.     End If
  149. Next
  150. Application.ScreenUpdating = True
  151.  
  152. End Sub
  153.  
  154.  
  155.  
  156. Sub ColorAllTabs()
  157. 'Declaration
  158. Dim iCntr, sht
  159.  
  160. 'This will hold the colorIndex number
  161. iCntr = 2
  162.  
  163. 'looping throgh the all the sheets of the workbook
  164. For Each sht In ActiveWorkbook.Worksheets
  165.     iCntr = iCntr + 1
  166.    
  167.     'Applying the colors to Sheet tabs
  168.    sht.Tab.ColorIndex = iCntr
  169. Next
  170.  
  171. End Sub
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement