User:Test user 0125/sandbox

Public Sub tester_new(db_sheet As String) 'Arrays Dim data_array As Currency Dim ent_arr As Currency Dim bus_arr As Currency Dim e_string_arr As String Dim string_arr As String ReDim data_array(3, 0) ReDim ent_arr(100, 3, 0) ReDim e_string_arr(100, 3, 0) ReDim bus_arr(100, 500, 3, 0) ReDim string_arr(100, 500, 3, 0) 'Counts Dim data_count As Integer Dim ent_count As Integer Dim bus_count As Integer 'Ranges Dim date_curr As Range Dim data_curr As Range Dim usd_curr As Range Dim ent_curr As Range Dim bus_curr As Range '  pushes listbox to an array we can use to compare Dim intf_newline As Integer Dim balcd_newline As Integer Dim sel_intfs(15) As String Dim sel_bal_cd(30) As String Dim intf_match As Integer Dim balcd_match As Integer '  Push Selected INTF's from ListBox1 to array(sel_intfs) For i = 0 To ActiveSheet.ListBox1.ListCount - 1 If ActiveSheet.ListBox1.Selected(i) Then sel_intfs(intf_newline) = ActiveSheet.ListBox1.List(i) intf_newline = intf_newline + 1 End If               Next i        '   Push Selected BAL_AMT from ListBox2 to array(sel_bal_cd) For i = 0 To ActiveSheet.ListBox2.ListCount - 1 If ActiveSheet.ListBox2.Selected(i) Then sel_bal_cd(balcd_newline) = ActiveSheet.ListBox2.List(i) balcd_newline = balcd_newline + 1 End If               Next i

'lets us be neater Dim fill As Range 'exists - needs to be reset to 0 for DATA_SRC_CD check

For ctr = start_row To rows

Set fill = Worksheets("Detail").Range(intf_col & ctr) Set date_curr = ActiveWorkbook.Sheets("Detail").Range(date_col & ctr) Set data_curr = ActiveWorkbook.Sheets("Detail").Range(data_col & ctr) Set usd_curr = ActiveWorkbook.Sheets("Detail").Range(bal_usd_col & ctr) Set ent_curr = ActiveWorkbook.Sheets("Detail").Range(ent_col & ctr) Set bus_curr = ActiveWorkbook.Sheets("Detail").Range(bus_unit_col & ctr) exists = 0 intf_match = 0 'check if intf matches For i = 0 To intf_newline - 1 If intf_match = 0 Then If fill = sel_intfs(i) Then intf_match = 1 End If           End If        Next i    'check if bal_cd matches If intf_match = 1 Then balcd_match = 0 For i = 0 To balcd_newline - 1 If Worksheets("Detail").Range(bal_cd_col & ctr) = sel_bal_cd(i) Then balcd_match = 1 End If           Next i        End If

If intf_match = 1 Then If balcd_match = 1 Then

'Part 1, DATA_SRC_CD 'They both match so we... check if 'data src cd' exists For i = 1 To UBound(data_array, 2) 'from 1 to max cols...               If data_array(0, i) = data_curr Then '...see if it exists, if so...                    exists = 1                          '...we set exists to 1 and... If Date1 = date_curr Then          '...find out which date it belongs too data_array(1, i) = data_array(1, i) + usd_curr ElseIf Date2 = date_curr Then      '...continuation data_array(2, i) = data_array(2, i) + usd_curr End If                   data_count = i                      'id of data is stored in data_count End If           Next i                                      'loop through until we check all of them 'after looping through data array, if exists = 0 then we have a new id           If exists = 0 Then ReDim Preserve data_array(3, UBound(data_array, 2) + 1) 'we redim the data_array so that it has an extra column data_array(0, UBound(data_array, 2)) = data_curr       'new column so the header for that column is the new data_src_cd If Date1 = date_curr Then             'finds if it matches date 1... data_array(1, i) = data_array(1, i) + usd_curr ElseIf Date2 = date_curr Then         '...or date 2 data_array(2, i) = data_array(2, i) + usd_curr End If                data_count = i                         'log the data_id in data_count using its column # in the data_array data_array(3, 0) = data_array(3, 0) + 1 'we add to the count of data id's by adding one to data_array(3,0) End If   'data_array ends so we reset exists, exists2 so we can use them again exists = 0 exists2 = 0

'Part 2, ENT_CD 'A. if ent_curr is a string...   If IsNumeric(ent_curr) = False Then '...then... 'B1...If not the first string entity If ent_arr(data_count, 0, 0) = data_curr Then 'If data_curr does exist then... (i.e. (this is not the first)) If ent_arr(data_count, 1, 0) <> 0 Then '...if our counter for string ent_cd's is not 0, one must exist in e_string_arr...               For i = 1 To ent_arr(data_count, 1, 0) '...so we check e_string_arr for the entity... (we could use Ubound(e_string_arr,3) but its not as efficient) If e_string_arr(data_count, 0, i) = CStr(ent_curr) Then 'As we loop through each column 'i', if header of column matches current_entity, then it already exists and we just add the usd_curr to the entry exists2 = 1 If Date1 = date_curr Then e_string_arr(data_count, 1, i) = CStr(Val(e_string_arr(data_count, 1, i)) + usd_curr) ElseIf Date2 = date_curr Then e_string_arr(data_count, 2, i) = CStr(Val(e_string_arr(data_count, 2, i)) + usd_curr) End If                       ent_count = i   'log the ent_id in ent_count using its column # within ent_arr of the data_count End If               Next i            'After checking all the entries in e_string_arr...                If exists2 = 0 Then '...if it didnt exist in that array then (we add it)... ent_arr(data_count, 1, 0) = ent_arr(data_count, 1, 0) + 1  '...we add 1 to the count of string entries in ent_arr e_string_arr(data_count, 3, 0) = CStr(CCur(e_string_arr(data_count, 3, 0)) + 1) '...we add 1 to the count of entries in e_string arr...                   If UBound(e_string_arr, 3) < Val(ent_arr(data_count, 1, 0)) Then '...and we check if there are less columns in ANY e_string_arr then there are strings in current ent_arr...                        ReDim Preserve e_string_arr(100, 3, (UBound(e_string_arr, 3) + 1)) 'if there are less columns then strings then we add 1. End If                   e_string_arr(data_count, 0, CCur(e_string_arr(data_count, 3, 0))) = CStr(ent_curr) 'using # of ent_id's counter in e_string_arr, we add the current ent id to the new column... If Date1 = date_curr Then '...then we add usd_curr to the right date e_string_arr(data_count, 1, e_string_arr(data_count, 3, 0)) = CStr(Val(e_string_arr(data_count, 1, e_string_arr(data_count, 3, 0))) + usd_curr) ElseIf Date2 = date_curr Then '...or date 2. e_string_arr(data_count, 2, e_string_arr(data_count, 3, 0)) = CStr(Val(e_string_arr(data_count, 2, e_string_arr(data_count, 3, 0))) + usd_curr) End If                   'since it didn't exist, we also have to add an entry in ent_arr for the id                    'Ent_arr code for a new string bus_id ent_arr(data_count, 3, 0) = ent_arr(data_count, 3, 0) + 1  'it didn't exist, it also changes the count of id's within ent_arr If UBound(ent_arr, 3) < ent_arr(data_count, 3, 0) Then 'if number of columns in ent_arr is less than new number ent id's in ent_arr...                       ReDim Preserve ent_arr(100, 3, (UBound(ent_arr, 3) + 1)) '...then we add 1 column to add the new info to it... End If                   ent_arr(data_count, 0, ent_arr(data_count, 3, 0)) = ent_arr(data_count, 1, 0) / 100 '...in the new column we made^, we put the new header of the ent_id within ent_arr for easy printing ent_count = ent_arr(data_count, 3, 0) End If           End If        End If        'B2...if the first string entity If ent_arr(data_count, 0, 0) <> data_curr Then 'If data_curr doesnt exist then this is the first entry... ent_arr(data_count, 0, 0) = data_curr     '...so put the data_curr in the header End If       If ent_arr(data_count, 1, 0) = 0 Then   'first string entity within this data_src_code e_string_arr(data_count, 0, 0) = data_curr 'Start by labeling e_string_arr with data_src_code e_string_arr(data_count, 3, 0) = CStr(Val(e_string_arr(data_count, 3, 0)) + 1) 'Add 1 to the counter of string id's           ent_arr(data_count, 3, 0) = ent_arr(data_count, 3, 0) + 1 'Add 1 to the number of ent id's that exist within ent_arr ent_arr(data_count, 1, 0) = ent_arr(data_count, 1, 0) + 1 'Add 1 to the number of string id's           If UBound(e_string_arr, 3) < CCur(e_string_arr(data_count, 3, 0)) Then 'if less columns than new number of ids then... ReDim Preserve e_string_arr(100, 3, (UBound(e_string_arr, 3) + 1)) '...we add 1 column to e_string_arr End If           If UBound(ent_arr, 3) < ent_arr(data_count, 3, 0) Then 'if ent_arr also has less columns than new id's... ReDim Preserve ent_arr(100, 3, (UBound(e_string_arr, 3) + 1)) 'we add 1 column to e_string_arr End If           e_string_arr(data_count, 0, CCur(e_string_arr(data_count, 3, 0))) = ent_curr 'we start the new column in e_string_arr with the ent id...            If Date1 = date_curr Then '...then if its date 1, add usd_curr... e_string_arr(data_count, 1, e_string_arr(data_count, 3, 0)) = CStr(Val(e_string_arr(data_count, 1, e_string_arr(data_count, 3, 0))) + usd_curr) ElseIf Date2 = date_curr Then '...if date 2, we add usd_curr... e_string_arr(data_count, 2, e_string_arr(data_count, 3, 0)) = CStr(Val(e_string_arr(data_count, 2, e_string_arr(data_count, 3, 0))) + usd_curr) End If           ent_arr(data_count, 0, ent_arr(data_count, 3, 0)) = ent_arr(data_count, 1, 0) / 100 ent_count = ent_arr(data_count, 3, 0) End If   End If

'B. if ent_curr is a number If IsNumeric(ent_curr) Then 'if ent_curr is a number then...       If ent_arr(data_count, 0, 0) = data_curr Then '...if the ent_arr has been initialized then...            exists = 1  '...set exists to 1... 'see if the ent_id already exists in the ent_arr For i = 1 To ent_arr(data_count, 3, 0) '...loop through the columns of ent arr to see if this ent_id already exists. If ent_arr(data_count, 0, i) = ent_curr Then 'if the header matches then the ent_id exists and... exists2 = 1 If Date1 = date_curr Then  '...add usd_curr to it. ent_arr(data_count, 1, i) = ent_arr(data_count, 1, i) + usd_curr ElseIf Date2 = date_curr Then ent_arr(data_count, 2, i) = ent_arr(data_count, 2, i) + usd_curr End If                   ent_count = i   'log the column # of the ent_id End If           Next i            'if ent_id does not exist in the ent_arr after the loop^...            If exists2 = 0 Then '...exists2 = 0 means doesnt exist...                ent_arr(data_count, 3, 0) = ent_arr(data_count, 3, 0) + 1 '...then we add 1 to the counter. If UBound(ent_arr, 3) < ent_arr(data_count, 3, 0) Then  'If the number of columns is less than the new number of ids... ReDim Preserve ent_arr(100, 3, (UBound(ent_arr, 3) + 1)) ' then we add 1 column End If               ent_arr(data_count, 0, ent_arr(data_count, 3, 0)) = ent_curr 'using the new counter, we put the ent_id in the top row... If Date1 = date_curr Then  'we add the proper usd ent_arr(data_count, 1, ent_arr(data_count, 3, 0)) = ent_arr(data_count, 1, ent_arr(data_count, 3, 0)) + usd_curr ElseIf Date2 = date_curr Then 'add the proper usd ent_arr(data_count, 2, ent_arr(data_count, 3, 0)) = ent_arr(data_count, 2, ent_arr(data_count, 3, 0)) + usd_curr End If               ent_count = ent_arr(data_count, 3, 0) 'log the proper ent_count End If       End If        'if ent_arr has not been intialized...        If exists = 0 Then  'if no entities then... ent_arr(data_count, 0, 0) = data_curr 'initialize ent_arr, put data_src_code in 0,0 ent_arr(data_count, 3, 0) = ent_arr(data_count, 3, 0) + 1 'add a column for the new id           If UBound(ent_arr, 3) < ent_arr(data_count, 3, 0) Then  'if # of column in ent_arr is less than new number of ids then... ReDim Preserve ent_arr(100, 3, (UBound(ent_arr, 3) + 1)) 'add 1 column End If           ent_arr(data_count, 0, ent_arr(data_count, 3, 0)) = ent_curr    'we start the new column in ent_arr with the ent id... If Date1 = date_curr Then '...then check for the right date and add usd_curr ent_arr(data_count, 1, ent_arr(data_count, 3, 0)) = ent_arr(data_count, 1, ent_arr(data_count, 3, 0)) + usd_curr ElseIf Date2 = date_curr Then '...then check for the right date and add usd_curr ent_arr(data_count, 2, ent_arr(data_count, 3, 0)) = ent_arr(data_count, 2, ent_arr(data_count, 3, 0)) + usd_curr End If           ent_count = ent_arr(data_count, 3, 0) 'log the right column# in ent_count End If   End If

'start bus section exists = 0 exists2 = 0

Dim exists_top As Integer Dim holder exists_top = 0 'A. if ent_curr is a string...   If IsNumeric(bus_curr) = False Then 'if bus_curr is a string then...        'needed for next step (should be a submodule but array does not exist in any other module... skip to next block) Select Case True Case IsNumeric(ent_curr) If bus_arr(data_count, ent_count, 0, 0) = ent_curr Then exists_top = 1 End If               Case Not (IsNumeric(ent_curr)) If bus_arr(data_count, ent_count, 0, 0) = ent_arr(data_count, 0, ent_count) Then exists_top = 1 End If           End Select 'after checking if bus_arr is titled properly, we can move on       If exists_top = 1 Then 'If ent_curr exists in this bus_arr...            If bus_arr(data_count, ent_count, 1, 0) <> 0 Then '...if string bus_codes exist then... For i = 1 To bus_arr(data_count, ent_count, 1, 0) '...loop through every column to find if the bus_code exists If string_arr(data_count, ent_count, 0, i) = CStr(bus_curr) Then 'if it exists then... exists2 = 1 If Date1 = date_curr Then 'date 1- check which date it matches string_arr(data_count, ent_count, 1, i) = CStr(Val(string_arr(data_count, ent_count, 1, i)) + usd_curr) ElseIf Date2 = date_curr Then 'date 2 - check which date it matches string_arr(data_count, ent_count, 2, i) = CStr(Val(string_arr(data_count, ent_count, 2, i)) + usd_curr) End If 'add usd_curr End If               Next i                If exists2 = 0 Then 'if it doesn't exist then... bus_arr(data_count, ent_count, 1, 0) = bus_arr(data_count, ent_count, 1, 0) + 1 '...we add 1 to count of string entries in bus_arr string_arr(data_count, ent_count, 3, 0) = CStr(Val(string_arr(data_count, ent_count, 3, 0)) + 1) '...we add 1 to the count of entries in string_arr If UBound(string_arr, 4) < (bus_arr(data_count, ent_count, 1, 0)) Then 'if number of columns in string_arr is less than new number of string ids then... ReDim Preserve string_arr(100, 500, 3, (UBound(string_arr, 4) + 1)) '...we add a new column to string_arr End If                   string_arr(data_count, ent_count, 0, CCur(string_arr(data_count, ent_count, 3, 0))) = CStr(bus_curr) 'using new number of bus ids, we add current bus id to new column If Date1 = date_curr Then 'add to proper date string_arr(data_count, ent_count, 1, string_arr(data_count, ent_count, 3, 0)) = CStr(Val(string_arr(data_count, ent_count, 1, string_arr(data_count, ent_count, 3, 0))) + usd_curr) ElseIf Date2 = date_curr Then 'add to proper date string_arr(data_count, ent_count, 2, string_arr(data_count, ent_count, 3, 0)) = CStr(Val(string_arr(data_count, ent_count, 2, string_arr(data_count, ent_count, 3, 0))) + usd_curr) End If                   'since it did not exist, we have to add 1 to count of bus ids in the bus_arr(3,0) 'bus_arr code for a new string bus id                   bus_arr(data_count, ent_count, 3, 0) = bus_arr(data_count, ent_count, 3, 0) + 1 If UBound(bus_arr, 4) < bus_arr(data_count, ent_count, 3, 0) Then 'if number of columns in bus_arr < # of ids in bus_arr then...                       ReDim Preserve bus_arr(100, 500, 3, (UBound(bus_arr, 4) + 1)) '... we add 1 column to add the new info to it. End If                   bus_arr(data_count, ent_count, 0, bus_arr(data_count, ent_count, 3, 0)) = bus_arr(data_count, ent_count, 1, 0) / 100 'with the new column, we put the current string # into it as a decimal End If           End If        End If        If exists_top = 0 Then 'If ent_curr does not exist, then... '...we must assign the proper id to the header Select Case True Case IsNumeric(ent_curr) bus_arr(data_count, ent_count, 0, 0) = ent_curr Case Not (IsNumeric(ent_curr)) bus_arr(data_count, ent_count, 0, 0) = ent_arr(data_count, 0, ent_count) End Select If Val(string_arr(data_count, ent_count, 1, 0)) = 0 Then 'If this is the first string entity then... string_arr(data_count, ent_count, 3, 0) = CStr(Val(string_arr(data_count, ent_count, 3, 0)) + 1) 'add 1 to the number of bus_codes within string_arr bus_arr(data_count, ent_count, 1, 0) = bus_arr(data_count, ent_count, 1, 0) + 1 'add 1 to the number of string id's within bus_arr bus_arr(data_count, ent_count, 3, 0) = bus_arr(data_count, ent_count, 3, 0) + 1 'add 1 to the number of entities within bus_arr If UBound(string_arr, 4) < Val(string_arr(data_count, ent_count, 3, 0)) Then 'if # of columns in string arr is less than number of entities in string_arr then... ReDim Preserve string_arr(100, 500, 3, (UBound(string_arr, 4) + 1)) '...add 1 column to string_arr End If               If UBound(bus_arr, 4) < bus_arr(data_count, ent_count, 3, 0) Then 'if bus_arr also has less columns than id's then... ReDim Preserve bus_arr(100, 500, 3, (UBound(bus_arr, 4) + 1)) 'add new column to bus_arr End If               string_arr(data_count, ent_count, 0, CCur(string_arr(data_count, ent_count, 3, 0))) = CStr(bus_curr) 'With new column, we push bus_id to header If Date1 = date_curr Then 'check if date 1 or... string_arr(data_count, ent_count, 1, string_arr(data_count, ent_count, 3, 0)) = CStr(Val(string_arr(data_count, ent_count, 1, string_arr(data_count, ent_count, 3, 0))) + usd_curr) ElseIf Date2 = date_curr Then 'if date 2 and add curr_usd. string_arr(data_count, ent_count, 2, string_arr(data_count, ent_count, 3, 0)) = CStr(Val(string_arr(data_count, ent_count, 2, string_arr(data_count, ent_count, 3, 0))) + usd_curr) End If           End If            bus_arr(data_count, ent_count, 0, bus_arr(data_count, ent_count, 3, 0)) = bus_arr(data_count, ent_count, 1, 0) / 100 End If   End If

If IsNumeric(bus_curr) Then 'needed for next step Select Case True Case IsNumeric(ent_curr) If bus_arr(data_count, ent_count, 0, 0) = ent_curr Then 'if numeric ent_curr, we just check against it                       exists_top = 1 End If               Case Not (IsNumeric(ent_curr)) If bus_arr(data_count, ent_count, 0, 0) = ent_arr(data_count, 0, ent_count) Then 'if not numeric, we must check if it exists using the decimal value assigned to ent_curr exists_top = 1 End If           End Select If exists_top = 1 Then 'if header exists, then it must already have an entry exists = 1 For i = 1 To bus_arr(data_count, ent_count, 3, 0) 'loop through bus arr to find if bus_cd exists If bus_arr(data_count, ent_count, 0, i) = bus_curr Then 'if it exists then... exists2 = 1 If Date1 = date_curr Then 'add usd_curr to right date... bus_arr(data_count, ent_count, 1, i) = bus_arr(data_count, ent_count, 1, i) + usd_curr ElseIf Date2 = date_curr Then 'date2 if date 1 is not right. bus_arr(data_count, ent_count, 2, i) = bus_arr(data_count, ent_count, 2, i) + usd_curr End If               End If            Next i            If exists2 = 0 Then 'if it does not exist then... bus_arr(data_count, ent_count, 3, 0) = bus_arr(data_count, ent_count, 3, 0) + 1 'add 1 to the number of ids in bus_arr If UBound(bus_arr, 4) < bus_arr(data_count, ent_count, 3, 0) Then 'if # of col's < new # of ids then... ReDim Preserve bus_arr(100, 500, 3, (UBound(bus_arr, 4) + 1)) 'add 1 column to bus_arr End If               bus_arr(data_count, ent_count, 0, bus_arr(data_count, ent_count, 3, 0)) = bus_curr 'push current bus code to new column If Date1 = date_curr Then 'add usd_curr to the right date... bus_arr(data_count, ent_count, 1, bus_arr(data_count, ent_count, 3, 0)) = bus_arr(data_count, ent_count, 1, bus_arr(data_count, ent_count, 3, 0)) + usd_curr ElseIf Date2 = date_curr Then 'date2, if date 1 is not right. bus_arr(data_count, ent_count, 2, bus_arr(data_count, ent_count, 3, 0)) = bus_arr(data_count, ent_count, 2, bus_arr(data_count, ent_count, 3, 0)) + usd_curr End If           End If        End If        If exists_top = 0 Then 'if header does not exist '...we must assign the proper id to the header Select Case True Case IsNumeric(ent_curr) bus_arr(data_count, ent_count, 0, 0) = ent_curr 'if numeric ent_curr, we can assign it to curr-based bus_arr Case Not (IsNumeric(ent_curr)) bus_arr(data_count, ent_count, 0, 0) = ent_arr(data_count, 0, ent_count) 'if not numeric, we must assign the fractional value End Select bus_arr(data_count, ent_count, 3, 0) = bus_arr(data_count, ent_count, 3, 0) + 1 If UBound(bus_arr, 4) < bus_arr(data_count, ent_count, 3, 0) Then 'if # of cols in bus_arr is < new # of ids in bus_arr then...               ReDim Preserve bus_arr(100, 500, 3, (UBound(bus_arr, 4) + 1)) '...add 1 column to bus_arr. End If           bus_arr(data_count, ent_count, 0, bus_arr(data_count, ent_count, 3, 0)) = bus_curr 'push current bus code to new column If Date1 = date_curr Then 'add usd_curr to right date... bus_arr(data_count, ent_count, 1, bus_arr(data_count, ent_count, 3, 0)) = bus_arr(data_count, ent_count, 1, bus_arr(data_count, ent_count, 3, 0)) + usd_curr ElseIf Date2 = date_curr Then 'date2, if date1 is not right. bus_arr(data_count, ent_count, 2, bus_arr(data_count, ent_count, 3, 0)) = bus_arr(data_count, ent_count, 2, bus_arr(data_count, ent_count, 3, 0)) + usd_curr End If       End If    End If End If  'intf_match End If 'bal_match

Next ctr 'Database difference section For ctr = 1 To data_array(3, 0) 'differences in data array data_array(3, ctr) = data_array(2, ctr) - data_array(1, ctr) 'differences in ent_arr For i = 1 To ent_arr(ctr, 3, 0) ent_arr(ctr, 3, i) = ent_arr(ctr, 2, i) - ent_arr(ctr, 1, i)       Next i        'differences in bus_arr For i = 1 To ent_arr(ctr, 3, 0) For ctr2 = 1 To bus_arr(ctr, i, 3, 0) bus_arr(ctr, i, 3, ctr2) = bus_arr(ctr, i, 2, ctr2) - bus_arr(ctr, i, 1, ctr2) Next ctr2 Next i   Next ctr

'Database largest section Dim largest_data As Currency Dim largest As Currency For ctr = 1 To data_array(3, 0) 'differences in data array data_array(3, ctr) = data_array(2, ctr) - data_array(1, ctr) 'differences in ent_arr If Abs(data_array(3, ctr)) > Abs(data_array(3, largest_data)) Then If data_array(0, ctr) <> 30461 Then largest_data = ctr End If           data_array(2, 0) = largest_data End If       For i = 1 To ent_arr(ctr, 3, 0) ent_arr(ctr, 3, i) = ent_arr(ctr, 2, i) - ent_arr(ctr, 1, i)           If Abs(ent_arr(ctr, 3, i)) > Abs(ent_arr(ctr, 3, largest)) Then largest = ctr End If           ent_arr(ctr, 2, 0) = largest Next i       'differences in bus_arr For i = 1 To ent_arr(ctr, 3, 0) For ctr2 = 1 To bus_arr(ctr, i, 3, 0) bus_arr(ctr, i, 3, ctr2) = bus_arr(ctr, i, 2, ctr2) - bus_arr(ctr, i, 1, ctr2) Next ctr2 Next i   Next ctr '  Printer Section Dim s_col As String Dim s_row As Integer Dim s_sheet As String Dim print_col As String s_col = "E" s_row = 1 s_sheet = db_sheet row_print = s_row print_col = s_col For i = 0 To data_array(3, 0) If i > 0 Then print_col = nextcol(print_col) End If       For ctr2 = 0 To 3 Sheets(s_sheet).Range(print_col & row_print + ctr2) = data_array(ctr2, i)       Next ctr2 Next i   For top_ctr = 1 To data_array(3, 0) row_print = ((4 * (top_ctr)) + top_ctr + 1) 'different from ((4*(2N-1)+N) because data_array takes spot 1           print_col = s_col        Sheets(s_sheet).Range("B" & row_print) = ent_arr(top_ctr, 0, 0)        For i = 0 To ent_arr(top_ctr, 3, 0)            If i > 0 Then                print_col = nextcol(print_col)            End If            For ctr2 = 0 To 3                If ent_arr(top_ctr, 0, i) > 0 And ent_arr(top_ctr, 0, i) < 1 Then                Sheets(s_sheet).Range(print_col & row_print + ctr2) = e_string_arr(top_ctr, ctr2, (100 * ent_arr(top_ctr, 0, i)))                Sheets(s_sheet).Range(print_col & row_print + 3) = Val(e_string_arr(top_ctr, 2, (100 * ent_arr(top_ctr, 0, i)))) - Val(e_string_arr(top_ctr, 1, (100 * ent_arr(top_ctr, 0, i))))                ElseIf ent_arr(top_ctr, 0, i) > 1 And ent_arr(top_ctr, 0, i) > 0 Then                Sheets(s_sheet).Range(print_col & row_print + ctr2) = ent_arr(top_ctr, ctr2, i)                End If            Next ctr2 Next i   Next top_ctr

Dim newrow As Integer newrow = 1 For toptop_ctr = 1 To data_array(3, 0) 'each data ID        'Print entity codes For top_ctr = 1 To ent_arr(toptop_ctr, 3, 0) 'each ent ID under data ID           new_row = new_row + 1 row_print = ((4 * (data_array(3, 0))) + data_array(3, 0) + 1) + ((4 * (new_row)) + new_row) print_col = s_col If ent_arr(toptop_ctr, 0, top_ctr) > 0 Then Sheets(s_sheet).Range("C" & row_print) = ent_arr(toptop_ctr, 0, 0) Sheets(s_sheet).Range("D" & row_print) = bus_arr(toptop_ctr, top_ctr, 0, 0) End If           If ent_arr(toptop_ctr, 0, top_ctr) < 1 And ent_arr(toptop_ctr, 0, top_ctr) > 0 Then Sheets(s_sheet).Range("C" & row_print) = ent_arr(toptop_ctr, 0, 0) Sheets(s_sheet).Range("D" & row_print) = e_string_arr(toptop_ctr, 0, (ent_arr(toptop_ctr, 0, top_ctr) * 100)) End If           'Print business codes For i = 0 To bus_arr(toptop_ctr, top_ctr, 3, 0) If i > 0 Then print_col = nextcol(print_col) End If               For ctr2 = 0 To 3 If i = 0 Then Sheets(s_sheet).Range(print_col & row_print + ctr2) = bus_arr(toptop_ctr, top_ctr, ctr2, i)               ElseIf i > 0 Then If bus_arr(toptop_ctr, top_ctr, 0, i) > 0 And bus_arr(toptop_ctr, top_ctr, 0, i) < 1 Then Sheets(s_sheet).Range(print_col & row_print + ctr2) = string_arr(toptop_ctr, top_ctr, ctr2, (100 * bus_arr(toptop_ctr, top_ctr, 0, i))) Sheets(s_sheet).Range(print_col & row_print + 3) = Val(string_arr(toptop_ctr, top_ctr, 2, (100 * bus_arr(toptop_ctr, top_ctr, 0, i)))) - Val(string_arr(toptop_ctr, top_ctr, 1, (100 * bus_arr(toptop_ctr, top_ctr, 0, i)))) ElseIf bus_arr(toptop_ctr, top_ctr, 0, i) > 1 And bus_arr(toptop_ctr, top_ctr, 0, i) > 0 Then Sheets(s_sheet).Range(print_col & row_print + ctr2) = bus_arr(toptop_ctr, top_ctr, ctr2, i)                   End If                End If                Next ctr2 Next i           ''Old method of printing string business codes ''String Business Codes 'If bus_arr(toptop_ctr, top_ctr, 1, 0) > 0 Then '  For ctr3 = 1 To bus_arr(toptop_ctr, top_ctr, 1, 0) '      print_col = nextcol(print_col) '      For ctr = 0 To 2 '          Sheets(s_sheet).Range(print_col & row_print + ctr) = string_arr(toptop_ctr, top_ctr, ctr, ctr3) '      Next ctr '      Sheets(s_sheet).Range(print_col & row_print + 3) = Val(string_arr(toptop_ctr, top_ctr, 2, ctr3)) - Val(string_arr(toptop_ctr, top_ctr, 1, ctr3)) '      Sheets(s_sheet).Range(s_col & row_print + 3) = Sheets(s_sheet).Range(s_col & row_print + 3) + 1 '  Next ctr3 'End If       Next top_ctr Next toptop_ctr

End Sub