Formatting raw data with extra rows automatically added in-between records

Withents

New Member
Joined
Nov 5, 2024
Messages
1
Office Version
  1. 365
Platform
  1. Windows
My company has an accounting software which spits out ugly reports. Traditionally, they have been exporting the raw data and then formatting everything manually. This particular report is listing payroll information where column A lists the employee, column B lists the project, column C lists the hours that were worked by that person on that project (there are a few other columns which list other information for that record, but you get the idea). The raw data is output with one header row at the top of all of the data. The company wants there to be essentially three rows in between each employee. A line for totals, a blank line that's filled with black (to mark the end of the employees record), and a line for the header row before the start of the next employee.

How on earth can I make it so that I can import the raw data and get the rows to generate between each employee without having to do it manually copy/paste? I thought about having the raw data on another tab and having a set of lookup functions in a formatted tab which would pull the info in, but each person has several different project lines they put time into. It can also change how many projects they are working on from pay period to pay period. Everyone has varying amounts of projects they are working on (some people have one and others have five).

Any advice or just generally pointing me in a direction would be helpful and much appreciated! TIA
 

Excel Facts

Why does 9 mean SUM in SUBTOTAL?
It is because Sum is the 9th alphabetically in Average, Count, CountA, Max, Min, Product, StDev.S, StDev.P, Sum, VAR.S, VAR.P.
Welcome to the MrExcel board!

You have not given us much about exactly what has to be totalled but see if something like this might be useful.

VBA Code:
Sub ReFormat()
  Dim cols As Long, r As Long
  Dim Hdrs As Range, rA As Range
  
  cols = Cells(1, Columns.Count).End(xlToLeft).Column
  Set Hdrs = Range("A1").Resize(, cols)
  For r = Cells(Rows.Count, 1).End(xlUp).Row - 1 To 2 Step -1
    If Cells(r, 1).Value <> Cells(r + 1, 1).Value Then
      Rows(r + 1).Resize(3).Insert
      Hdrs.Copy Destination:=Cells(r + 3, 1)
      Cells(r + 2, 1).Resize(, cols).Interior.Color = vbBlack
    End If
  Next r
  For Each rA In Range("D2", Range("D" & Rows.Count).End(xlUp)).SpecialCells(xlConstants, xlNumbers).Areas
    rA.Cells(rA.Count + 1).Formula2 = "=SUM(" & rA.Address & ")"
    Cells(rA.Row + rA.Count, "A").Value = "Total"
  Next rA
End Sub

My sample data before:

Withents.xlsm
ABCDE
1EmployeeData 1Data 2ValueData 4
2Name 1datadata3data
3Name 1datadata2data
4Name 1datadata5data
5Name 2datadata6data
6Name 3datadata1data
7Name 3datadata2data
8Name 3datadata4data
9Name 3datadata8data
10Name 3datadata7data
11Name 4datadata1data
12Name 4datadata2data
Sheet1


.. and after:

Withents.xlsm
ABCDE
1EmployeeData 1Data 2ValueData 4
2Name 1datadata3data
3Name 1datadata2data
4Name 1datadata5data
5Total10
6
7EmployeeData 1Data 2ValueData 4
8Name 2datadata6data
9Total6
10
11EmployeeData 1Data 2ValueData 4
12Name 3datadata1data
13Name 3datadata2data
14Name 3datadata4data
15Name 3datadata8data
16Name 3datadata7data
17Total22
18
19EmployeeData 1Data 2ValueData 4
20Name 4datadata1data
21Name 4datadata2data
22Total3
Sheet1
Cell Formulas
RangeFormula
D5D5=SUM($D$2:$D$4)
D9D9=SUM($D$8)
D17D17=SUM($D$12:$D$16)
D22D22=SUM($D$20:$D$21)
 
Upvote 0

Forum statistics

Threads
1,224,804
Messages
6,181,059
Members
453,016
Latest member
cherryfalling

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