reformatting data extract

ajm

Well-known Member
Joined
Feb 5, 2003
Messages
2,005
Office Version
  1. 365
Platform
  1. Windows
folks,

i need to reformat a report extracted from our ERP. the report gives me accommodation revenue by fee type for each particular room type. if printed from the ERP, the report is formatted to print each accommodation class on new page with a column for each fee type. The number of bed days and accommodation classification are above the revenue table. Below the table is another table for Previous Months Adjustments.

1Classification : ABC PATIENT FUND TOTALS
2------- ---- ------
3
4Current Month : Accom. Profess. Other Accom. Profess. Other Totals
5Fees Fees
6
7Bed Days : 456
8
9Amount Raised 0.00 0.00 0.00 0.00 0.00 0.00 0.00
10Pre-Admission Deposits 0.00 0.00 0.00 0.00 0.00 0.00 0.00
11Receipts 0.00 0.00 0.00 0.00 0.00 0.00 0.00
12Pre-Admission Refunds 0.00 0.00 0.00 0.00 0.00 0.00 0.00
13Refunds 0.00 0.00 0.00 0.00 0.00 0.00 0.00
14JNL:MONTH/S PRIOR ADJUSTMENT 0.00 0.00 0.00 0.00 0.00 0.00 0.00
15---------- ---------- ---------- ---------- ---------- ---------- -----------
160.00 0.00 0.00 0.00 0.00 0.00 0.00
17==================================================================================================================================
18
19Previous Months Adjustments: Accom. Profess. Other Accom. Profess. Other Totals
20Fees Fees
21
22Bed Days : 108
23
24Amount Raised 0.00 0.00 0.00 0.00 0.00 0.00 0.00
25Pre-Admission Deposits 0.00 0.00 0.00 0.00 0.00 0.00 0.00
26Receipts 0.00 0.00 0.00 0.00 0.00 0.00 0.00
27Pre-Admission Refunds 0.00 0.00 0.00 0.00 0.00 0.00 0.00
28Refunds 0.00 0.00 0.00 0.00 0.00 0.00 0.00
29---------- ---------- ---------- ---------- ---------- ---------- -----------
300.00 0.00 0.00 0.00 0.00 0.00 0.00
31==================================================================================================================================

<tbody>
</tbody>


I have included row numbering to indicate the standard number of rows between each data row.

What I want to do is to separate the fee amounts into columns and to use the Classification, month and number of bed days as columns themselves. Below is the end result i want to create.

ClassificationMonthBed DaysCurrent Month :Accom.Profess.OtherAccom.Profess.OtherTotals

<tbody>
</tbody>
FeesFees
ABCCurrent Month :456Amount Raised0000000
ABCCurrent Month :456Pre-Admission Deposits0000000
ABCCurrent Month :456Receipts0000000
ABCCurrent Month :456Pre-Admission Refunds0000000
ABCCurrent Month :456Refunds0000000
ABCPrevious Months Adjustments:Amount Raised0000000
ABCPrevious Months Adjustments:Pre-Admission Deposits0000000
ABCPrevious Months Adjustments:Receipts0000000
ABCPrevious Months Adjustments:Pre-Admission Refunds0000000
ABCPrevious Months Adjustments:Refunds0000000
==================================================================================================================================

<tbody>
</tbody>

The text to columns part is easy:
Code:
Dim sFileName As String    'Show the open dialog and pass the selected file name to the String variable "sFileName"
    sFileName = Application.GetOpenFilename
    'They have cancelled.
    If sFileName = "False" Then Exit Sub
    Workbooks.OpenText Filename:=sFileName, Origin:=xlMSDOS, StartRow:=1, DataType:=xlFixedWidth, FieldInfo:=Array( _
        Array(0, 1), Array(33, 1), Array(47, 1), Array(61, 1), Array(64, 1), Array(75, 1), Array(89 _
        , 1), Array(103, 1), Array(117, 1)), TrailingMinusNumbers:=True

its the moving of Classification, Month and Bed days that is vexing me.

<!-- Table easily created from Excel with ASAP Utilities (https://www.asap-utilities.com) -->
 
Last edited:

Excel Facts

Fastest way to copy a worksheet?
Hold down the Ctrl key while dragging tab for Sheet1 to the right. Excel will make a copy of the worksheet.
no takers?

a bit more information. its a long report and i was mistaken about the number of rows per classification being static. In both the Current Month and Previous Months Adjustment sections there can be extra rows inserted which contain other financial information. The report header, which i didn't include in the extract above, signifies the start of each new page in the report. each page contains only one class of accommodation. the current month details are easy enough to pick up as they are always the same number of rows below the header. the Prev Months then is the harder part.

so, approach today is to see if i can write a loop that looks for each header then offsets down two rows to pick up the accomm class, down another three rows for the Current Month title, then down another three rows for the bed days, and finally another two rows for the amounts. then, do a find to get "Previous Months Adjustments" location and repeat the offsets.

its going to be ugly if i can get it to work. but, i've been called worse things:eek:
 
Upvote 0
this so far:

Code:
Sub test()

Dim CurrMth As String, Class As String, Beds As String, CMAmtRsd As String, PMBedDays As String, PMAmtRsd As String


Dim Rng As Range
Dim c As Range, d As Range
Dim pasteCell As Range
Dim DestSht As Worksheet


'Dim sFileName As String    'Show the open dialog and pass the selected file name to the String variable "sFileName"
    'sFileName = Application.GetOpenFilename
    'They have cancelled.
    'If sFileName = "False" Then Exit Sub
   ' Workbooks.OpenText Filename:=sFileName, Origin:=xlMSDOS, StartRow:=1, DataType:=xlFixedWidth, FieldInfo:=Array( _
        Array(0, 1), Array(33, 1), Array(47, 1), Array(61, 1), Array(64, 1), Array(75, 1), Array(89 _
        , 1), Array(103, 1), Array(117, 1)), TrailingMinusNumbers:=True
 Set DestSht = Worksheets("AmtsRaised")
        
  CurrMth = Trim(Right(ActiveSheet.Range("c2"), 6))
  
  Set Rng = ActiveSheet.Range("a1", Range("a1048576").End(xlUp))
With Rng
    Set c = .Find("DEBT2.P33", LookIn:=xlValues)
    Set d = .Find("Previous Months Adjustments:", LookIn:=xlValues)
            
    If Not c Is Nothing Then
        firstAddress = c.Address
        
        Do
        Class = Trim(Right(c.Offset(2, 0).Value, Len(c.Offset(2, 0).Value) - InStr(c.Offset(2, 0).Value, ":")))
        Beds = Trim(Right(c.Offset(8, 0).Value, Len(c.Offset(8, 0).Value) - InStr(c.Offset(8, 0).Value, ":")))
        CMAmtRsd = Trim(c.Offset(10, 7).Value)
        PMBedDays = Trim(Right(d.Offset(3, 0).Value, Len(d.Offset(3, 0).Value) - InStr(d.Offset(3, 0).Value, ":")))
        PMAmtRsd = Trim(d.Offset(5, 7).Value)
             
      '///Set the variable to the first empty cell in Row 2
     
     With DestSht
     Set pasteCell = .Range("b1048576").End(xlUp).Offset(1, 0)

     'Copy and paste
     pasteCell.Value = CurrMth
     pasteCell.Offset(0, 1).Value = Beds
     pasteCell.Offset(0, 2).Value = Class
     pasteCell.Offset(0, 3).Value = CMAmtRsd
     pasteCell.Offset(1, 0).Value = CurrMth
     pasteCell.Offset(1, 1).Value = PMBedDays
     pasteCell.Offset(1, 2).Value = Class
     pasteCell.Offset(1, 3).Value = PMAmtRsd
     
     End With
     '///Sheets("Sheet1").Range("A2:B10").Copy Destination:=pasteCell
        
            Set c = .FindNext(c)
            Set d = .FindNext(d)
        Loop While Not c Is Nothing And c.Address <> firstAddress
    End If
End With


End Sub

I have changed the final result to pulling just the amounts raised per accommodation class and posting to the next page:


MonthBed DaysClassificationAmount
Current Month4366463ABC0
Previous Months Adjustments:43664ABC0

<tbody>
</tbody>


However, when i am having trouble with the find inside a find, i think. the first run through gives perfect results but when resetting c and d, they both become the same. what have i done wrong?

I am going to post a new question focusing on this double use of FindNext so it doesn't disappear in this thread.
 
Last edited:
Upvote 0

Forum statistics

Threads
1,214,952
Messages
6,122,458
Members
449,085
Latest member
ExcelError

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