Advertisement
Guest User

macro

a guest
Mar 21st, 2017
53
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. Private Sub CommandButton1_Click()
  2.     'Define Workbook And Sheet For Parsing
  3.    Dim wb As Workbook
  4.     Dim ws As Worksheet
  5.     Dim twb As Workbook
  6.     Dim tws As Worksheet
  7.    
  8.     Set wb = Workbooks.Open("G:\Spero\Utilities\BB Class List Base.xlsx")
  9.     Set ws = wb.Worksheets("program_status_report")
  10.     Set twb = ThisWorkbook
  11.     Set tws = ThisWorkbook.Worksheets("Sheet1")
  12.    
  13.     'Classify Different Status Types
  14.    Dim i As Long
  15.     Dim statusTypes(16) As String
  16.     Dim statusTypeCount(16) As Integer
  17.     Dim numStatusTypes As Integer
  18.     Dim element As Variant
  19.     Dim element2 As Variant
  20.     Dim match As Boolean
  21.    
  22.     numStatusTypes = 0
  23.    
  24.     For i = 4 To ws.Rows.count
  25.         If Not IsEmpty(ws.Cells(i, 4)) Then
  26.             match = False
  27.             Dim mStr As String
  28.             Dim count As Integer
  29.             mStr = ws.Cells(i, 4)
  30.             count = 0
  31.            
  32.             For Each element In statusTypes
  33.                 count = count + 1
  34.                 If (mStr = element) Then
  35.                     match = True
  36.                     statusTypeCount(count) = statusTypeCount(count) + 1
  37.                     tws.Cells(count - 1, 5) = statusTypeCount(count) + 1
  38.                 End If
  39.             Next element
  40.            
  41.             If (match = False) Then
  42.                 numStatusTypes = numStatusTypes + 1
  43.                 statusTypes(numStatusTypes) = ws.Cells(i, 4)
  44.                 tws.Cells(numStatusTypes, 4) = ws.Cells(i, 4)
  45.             End If
  46.         End If
  47.     Next i
  48.    
  49.     'Priority For Organization
  50.    Dim priority(16) As String
  51.     priority(1) = "Phase 1"
  52.     priority(2) = "Phase 2"
  53.     priority(3) = "Phase 3"
  54.     priority(4) = "Phase 4"
  55.     priority(5) = "Class 1"
  56.     priority(6) = "Class 2"
  57.     priority(7) = "Class 3"
  58.     priority(8) = "Class 4"
  59.     priority(9) = "Class 5"
  60.     priority(10) = "Class 6"
  61.     priority(11) = "Transition"
  62.     priority(12) = "Advanced 1"
  63.     priority(13) = "Advanced 2"
  64.    
  65.     Dim extraStatus(16) As String
  66.     Dim numExtraStatus As Integer
  67.     Dim curRows As Integer
  68.    
  69.     curRows = 1
  70.     numExtraStatus = 0
  71.    
  72.     For Each element2 In priority
  73.         Dim its As Integer
  74.         its = 0
  75.         For Each element In statusTypes
  76.             its = its + 1
  77.             If (UCase(element2) = UCase(element)) And (its <= 16) Then
  78.                 Dim x As Integer
  79.                 tws.Cells(curRows, 1) = element
  80.                 x = curRows + (statusTypeCount(its) \ 4)
  81.                 curRows = x + 2
  82.             End If
  83.         Next element
  84.     Next element2
  85.    
  86.     'Row Iteration Variables
  87.    Dim rw As Range
  88.     Dim RowCount As Integer
  89.    
  90.     RowCount = 4
  91.    
  92.     For Each rw In ws.Rows
  93.         Dim nameStr As String
  94.         If Not IsEmpty(ws.Cells(RowCount, 2)) Then
  95.             'tws.Cells(RowCount - 3, 1) = ws.Cells(RowCount, 2) & " " & ws.Cells(RowCount, 3)
  96.        End If
  97.         If Not IsEmpty(ws.Cells(RowCount, 1)) Then
  98.             'tws.Cells(RowCount - 3, 2) = ws.Cells(RowCount, 1)
  99.        Else
  100.             Exit For
  101.         End If
  102.         RowCount = RowCount + 1
  103.     Next rw
  104.    
  105.     'Close Unparsed Workbook
  106.    Call wb.Close(False)
  107.    
  108. End Sub
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement