Unconsolidate data

bmatthewstevens

New Member
Joined
Nov 21, 2022
Messages
9
Office Version
  1. 365
Platform
  1. Windows
I have tried my hand at macos, and what's left of my hair is starting to fall out... could anyone help me with a macro to unconsolidate an excel file? If it was only a few I would just do it by hand, but I'm filling in for a co-worker who quit and this is nothing that I've done before, I'm in networking.

Here is what I have

GL NumberIVNUMCharge DescriptionFinancial ClassQtyChargesTotal QtyTotal Charges
10000.00099003BALANCE TRANSFERMEDICARE
658​
2,844.62
10000.000MEDICAID
42​
3,106.39
10000.000BLUE CROSS
692​
(2,576.55)
10000.000COMMERCIAL
643​
(4,903.98)
10000.000HMO/PPO-
10000.000PRIVATE
1022​
1,614.98
3057​
85.46
10203.0009903000TRANSFERS TO/ FROM SURGERY CLINICMEDICARE-
10203.000MEDICAID-
10203.000BLUE CROSS
1​
148.15
10203.000COMMERCIAL-
10203.000HMO/PPO-
10203.000PRIVATE-
1​
148.15
10234.00099006REFUND FROM ARMEDICARE
62​
35,987.42
10234.000MEDICAID
27​
2,336.62
10234.000BLUE CROSS
441​
56,376.17
10234.000COMMERCIAL
119​
33,105.98
10234.000HMO/PPO-
10234.000PRIVATE
13​
1,141.38
662​
128,947.57




Here is what I need it to look like.

GLNUMIVNUMDescMedicare QTYMedicare AMTMedicaid QTYMedicaid AMTBC QTYBC AMTCOM QTYCOM AMTPP QTYPP AMTTOTAL QTYTOTAL
10000.00099003BALANCE TRANSFER392$46.408$0.00328$44.02295-$148.66189$11.791212-$46.45
10203.0009903000TRANSFERS TO/ FROM SURGERY CLINIC$0.00$0.005-$143.48$0.001-$26.286-$169.76
10234.00099006REFUND FROM AR55$9,876.787$388.28138$14,858.1758$25,350.245$226.84263$50,700.31
 
Apart from the change below, Johnny's code seems to be working ok on my machine.
Have you rebooted your machine and tried running it again ?

The code does all the output it one go, so how are you determining it is 20% done ?

If it is still erroring out add this 2nd line below after the line shown and tell us what it says.
Rich (BB code):
    SourceArray = SourceWS.Range("A2:H" & SourceWS.Cells.Find("*", , xlFormulas, , xlByRows, xlPrevious).Row)           ' Load source data into 2D 1 based SourceArray
    '  Add this line to test the Last Row / Size
    MsgBox "SourceArray Rows " & UBound(SourceArray, 1)

The change you need to make to his code is to swap out replace "-" xlPart with xlWhole ie
as it stands it is converting your negatives to positives.
Rich (BB code):
    With ActiveSheet.UsedRange
        .Replace "-", 0, xlWhole, , , , False, False                                                                     ' Replace the dashes with zeros
        .Value = .Value
   End With
 
Upvote 0

Excel Facts

Does the VLOOKUP table have to be sorted?
No! when you are using an exact match, the VLOOKUP table can be in any order. Best-selling items at the top is actually the best.
Apart from the change below, Johnny's code seems to be working ok on my machine.
Have you rebooted your machine and tried running it again ?

The code does all the output it one go, so how are you determining it is 20% done ?

If it is still erroring out add this 2nd line below after the line shown and tell us what it says.
Rich (BB code):
    SourceArray = SourceWS.Range("A2:H" & SourceWS.Cells.Find("*", , xlFormulas, , xlByRows, xlPrevious).Row)           ' Load source data into 2D 1 based SourceArray
    '  Add this line to test the Last Row / Size
    MsgBox "SourceArray Rows " & UBound(SourceArray, 1)

The change you need to make to his code is to swap out replace "-" xlPart with xlWhole ie
as it stands it is converting your negatives to positives.
Rich (BB code):
    With ActiveSheet.UsedRange
        .Replace "-", 0, xlWhole, , , , False, False                                                                     ' Replace the dashes with zeros
        .Value = .Value
   End With


I am figuring the 20% because i have 28,000 lines that it needs to turn into like 6-7 thousand,... it will turn 4500 into 800 lines perfect. but then it throws the memory error.
 
Upvote 0
Did you try including the message box line ? What number of rows is the msgbox showing ?
 
Upvote 0
That totally fixed it...

I don't know how to mark both of yours as a solution, but you guys seriously saved me days of manual work...

How can I buy you a beer?
 
Upvote 0
well I found one of the charge descriptions had the data surrounded by =>data>=

that was freaking the code out it looks like, I ran a simple find and replace removed them all and it worked like a charm.
 
Upvote 0
The change you need to make to his code is to swap out replace "-" xlPart with xlWhole ie
as it stands it is converting your negatives to positives.
Rich (BB code):
    With ActiveSheet.UsedRange
        .Replace "-", 0, xlWhole, , , , False, False                                                                     ' Replace the dashes with zeros
        .Value = .Value
   End With
Nice catch @Alex Blakenburg!

Here is a corrected version:
VBA Code:
Sub ConsolidateV2()
'
    Dim ResultsSheetMissing     As Boolean
    Dim ArrayRow                As Long, DestinationRow     As Long
    Dim ResultsSheetName        As String
    Dim DestinationArray()      As Variant, SourceArray     As Variant
    Dim HeaderTitlesToPaste     As Variant
    Dim DestinationWS           As Worksheet, SourceWS      As Worksheet
'
'-----------------------------------------------------------------------------------------------------------------------
'
    ResultsSheetName = "Results Sheet"                                                                                  ' <--- Set this to the name of the destination sheet
    Set SourceWS = Sheets("Sheet1")                                                                                     ' <--- Set this to the name of the source sheet
'

'
'-----------------------------------------------------------------------------------------------------------------------
'
    HeaderTitlesToPaste = Array("GLNUM", "IVNUM", "Charge Desc", "Medicare QTY", "Medicare AMT", "Medicaid QTY", _
            "Medicaid AMT", "BC QTY", "BC AMT", "COM QTY", "COM AMT", "HMO/PPO QTY", "HMO/PPO AMT", "Private QTY", _
            "Private AMT", "Total Qty", "Total Charges")                                                                ' Header row to paste to destination sheet
'
    ResultsSheetMissing = Evaluate("IsError(Cell(""col"",'" + ResultsSheetName + "'!A1))")                              ' If ResultsSheetMissing = False then the sheet does exist
'
    If ResultsSheetMissing = False Then                                                                                 ' If the ResultsSheetName exists then
        Application.DisplayAlerts = False                                                                               '   Turn DisplayAlerts off ... sheet deletion causes popup
        Sheets(ResultsSheetName).Delete                                                                                 '   Delete the sheet
        Application.DisplayAlerts = True                                                                                '   Turn DisplayAlerts back on
    End If
'
    Sheets.Add(After:=Sheets(Sheets.Count)).Name = ResultsSheetName                                                     ' Add the ResultsSheet & name it
    Set DestinationWS = Sheets(ResultsSheetName)                                                                        ' Set the DestinationWS
'
    SourceArray = SourceWS.Range("A2:H" & SourceWS.Cells.Find("*", , xlFormulas, , xlByRows, xlPrevious).Row)           ' Load source data into 2D 1 based SourceArray
'
    ReDim DestinationArray(1 To UBound(SourceArray, 1), 1 To 17)
'
    DestinationRow = 0                                                                                                  ' Initialize DestinationRow
'
    For ArrayRow = 1 To UBound(SourceArray, 1) Step 6                                                                   ' Loop through the SourceArray rows
        DestinationRow = DestinationRow + 1                                                                             '   Increment DestinationRow
        DestinationArray(DestinationRow, 1) = SourceArray(ArrayRow, 1)                                                  '   GLNUM
        DestinationArray(DestinationRow, 2) = SourceArray(ArrayRow, 2)                                                  '   IVNUM
        DestinationArray(DestinationRow, 3) = SourceArray(ArrayRow, 3)                                                  '   Charge Desc
        DestinationArray(DestinationRow, 4) = SourceArray(ArrayRow, 5)                                                  '   Medicare QTY
        DestinationArray(DestinationRow, 5) = SourceArray(ArrayRow, 6)                                                  '   Medicare AMT
        DestinationArray(DestinationRow, 6) = SourceArray(ArrayRow + 1, 5)                                              '   Medicaid QTY
        DestinationArray(DestinationRow, 7) = SourceArray(ArrayRow + 1, 6)                                              '   Medicaid AMT
        DestinationArray(DestinationRow, 8) = SourceArray(ArrayRow + 2, 5)                                              '   BC QTY
        DestinationArray(DestinationRow, 9) = SourceArray(ArrayRow + 2, 6)                                              '   BC AMT
        DestinationArray(DestinationRow, 10) = SourceArray(ArrayRow + 3, 5)                                             '   COM QTY
        DestinationArray(DestinationRow, 11) = SourceArray(ArrayRow + 3, 6)                                             '   COM AMT
        DestinationArray(DestinationRow, 12) = SourceArray(ArrayRow + 4, 5)                                             '   HMO/PPO QTY
        DestinationArray(DestinationRow, 13) = SourceArray(ArrayRow + 4, 6)                                             '   HMO/PPO AMT
        DestinationArray(DestinationRow, 14) = SourceArray(ArrayRow + 5, 5)                                             '   Private QTY
        DestinationArray(DestinationRow, 15) = SourceArray(ArrayRow + 5, 6)                                             '   Private AMT
        DestinationArray(DestinationRow, 16) = SourceArray(ArrayRow + 5, 7)                                             '   Total Qty
        DestinationArray(DestinationRow, 17) = SourceArray(ArrayRow + 5, 8)                                             '   Total Charges
    Next                                                                                                                ' Loop back
'
    DestinationWS.Range("A1:Q1").Value = HeaderTitlesToPaste                                                            ' Write header row to DestinationSheet
'
    DestinationWS.Range("A2").Resize(UBound(DestinationArray, 1), UBound(DestinationArray, 2)) = DestinationArray       ' Write the DestinationArray to the destination sheet
'
    DestinationWS.Columns("A:A").NumberFormat = "0.000"                                                                 ' Format column A in the destination sheet to 3 decimal places
'
    DestinationWS.Range("E:E,G:G,I:I,K:K,M:M,O:O,Q:Q").NumberFormat = "#,##0.00_);(#,##0.00)"                           ' Format the Amount columns on the destination sheet
'
    ActiveSheet.UsedRange.Replace "-", 0, xlWhole, , , , False, False                                                   ' Replace the dashes with zeros
'
    DestinationWS.UsedRange.Columns.AutoFit                                                                             ' Autofit the widths of all used columns
End Sub
 
Upvote 0

Forum statistics

Threads
1,217,414
Messages
6,136,480
Members
450,016
Latest member
murarj

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top