Advertisement
Guest User

Untitled

a guest
Dec 31st, 2018
90
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. Sub TrackingReport()
  2.    
  3.    
  4.     Dim LCWB As Workbook
  5.     Dim Trackingbook As Workbook
  6.     Dim i As Integer
  7.     Dim rng As Range
  8.     Dim lastinTrackingbook As Integer
  9.     Dim LastInCurrSheet As Integer
  10.     LCWBLoc = "B:\Loads covered spreadsheet\Loads Covered.xlsm"
  11.     TrackingbookLoc = "B:\Loads covered spreadsheet\Tracking.xlsx"
  12.     Set Trackingbook = Workbooks.Open(TrackingbookLoc)
  13.     Set LCWB = Workbooks.Open(LCWBLoc)
  14.     Application.ScreenUpdating = False
  15. 'ReportView
  16.    AllDAtaSheetExist = False
  17.     For Each Sh In Trackingbook.Worksheets
  18.         If Sh.Name = "ALL DATA For Tracking" Then: AllDAtaSheetExist = True
  19.     Next
  20.    
  21.     If AllDAtaSheetExist = True Then
  22.        
  23.         Trackingbook.Sheets("ALL DATA For Tracking").UsedRange.Clear
  24.        
  25.     Else
  26.        
  27.         Trackingbook.Worksheets.Add().Name = "ALL DATA For Tracking"
  28.        
  29.     End If
  30.    
  31.    
  32. '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
  33.    
  34.  'so this approach is to evaluate the cell value and opnly copy over rows with desired status codes.
  35.    
  36.    
  37. For Each Sh In ThisWorkbook.Worksheets
  38.  
  39.       If InStr(1, Sh.Name, "-") > 0 Then
  40.        
  41.         LastInCurrSheet = Sh.Cells(1000, 2).End(xlUp).Row
  42.  
  43.         For i = 3 To LastInCurrSheet
  44.        
  45.        
  46.        
  47.         Select Case Cells(i, 2).Value
  48.         Case vbNullString
  49.         Case "GO TO LOAD", "SHIPMENT_DELIVERED", "SHIPMENT_DRY_VAN_CHARGE", "" 'Note nothing is done in this case
  50.        Case Else
  51.             Sh.Rows(i).Copy
  52.             lastinTrackingbook = Trackingbook.Sheets("ALL DATA For Tracking").Cells(100000, 2).End(xlUp).Row
  53.             Trackingbook.Sheets("ALL DATA For Tracking").Cells(lastinTrackingbook + 1, 1).PasteSpecial xlPasteValues
  54.     End Select
  55.        
  56.        
  57.        
  58.            
  59. '                If ((Cells(i, 2).Value = "SHIPMENT_DELIVERED") Or (Cells(i, 2).Value = "SHIPMENT_DRY_VAN_CHARGE")) Then
  60. ''do nothing
  61. '                Else
  62. '                Sh.Rows(i).Copy
  63. '                lastinTrackingbook = Trackingbook.Sheets("ALL DATA For Tracking").Cells(100000, 2).End(xlUp).Row
  64. '                Trackingbook.Sheets("ALL DATA For Tracking").Cells(lastinTrackingbook + 1, 1).PasteSpecial xlPasteValues
  65. '                End If
  66.                Next
  67.  
  68. End If
  69. Next
  70.    
  71.   '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
  72.    
  73.  ' this approach copies everything over, then deletes blank lines, and undesired status codes
  74.  
  75. '    For Each Sh In ThisWorkbook.Worksheets
  76. '
  77. '        If InStr(1, Sh.Name, "-") > 0 Then
  78. '            lastinTrackingbook = Trackingbook.Sheets("ALL DATA For Tracking").Cells(100000, 2).End(xlUp).Row
  79. '            LastInCurrSheet = Sh.Cells(1048576, 1).End(xlUp).Row
  80. '
  81. '            Sh.Range("A2:O" & LastInCurrSheet).Copy
  82. '
  83. '            Trackingbook.Sheets("ALL DATA For Tracking").Cells(lastinTrackingbook + 1, 1).PasteSpecial xlPasteValues
  84. '
  85. '        End If
  86. '        lastinTrackingbook = ""
  87. '        LastInCurrSheet = ""
  88. '    Next
  89. '
  90. '    Trackingbook.Sheets("ALL DATA For Tracking").Activate
  91.    
  92.    
  93.    
  94. 'This Removes Headers ( Except the first one, the actual header)
  95.    
  96. '    For i = 3 To lastinTrackingbook
  97. '        If Cells(i, 1).Value = "Email" Then
  98. '            Rows(i).Delete
  99. '        End If
  100. '
  101. '    Next
  102. '
  103. '    MsgBox (lastinTrackingbook) ' this returns the correct row
  104. '    For i = 2 To lastinTrackingbook
  105. '
  106. '        If Cells(i, 3) = "" Then
  107. 'If Cells(i, 3) = vbNullString Then
  108. '
  109. '            Rows(i).Delete
  110. '        End If
  111. '        If Cells(i, 2) = "SHIPMENT_DELIVERED" Then
  112. '            Rows(i).Delete
  113. '        End If
  114. '    Next
  115. '
  116. '    Rows(1).Delete
  117.    
  118.     'Range("D2", "E" & lastinTrackingbook).NumberFormat = "MM-DD-YY"
  119.    
  120.    
  121.    
  122.    
  123.    
  124.    
  125.    
  126.    
  127.    
  128.    
  129.    
  130.    
  131.    
  132.    
  133.    
  134.     Application.ScreenUpdating = True
  135. End Sub
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement