Extrapolating Columns into Duplicate Lines

gimmick18

New Member
Joined
Aug 14, 2019
Messages
5
Office Version
  1. 365
Platform
  1. Windows
Hi Experts,

I have something I am struggling to get my head around in terms of Macro code, and wondered if I could ask for help. Sample data below;

Wo NoDirectiveActual CompletionReference NoNtOt1Ot2Ot3Ot4Ns
92034Full Overhaul KRV1025618 36-SV-1623B 8.75 6x1012/08/2019AG1018339110.5230.51

<tbody>
</tbody>


This is an export from a system that highlights the number of hours worked by various staff Rates (Nt, Ot1, Ot2 etc...).

The output from this needs to show a separate line for each Rate, therefore replicating the contents to produce this;

Wo NoDirectiveActual CompletionReference NoRateHours
92034Full Overhaul KRV1025618 36-SV-1623B 8.75 6x1012/08/2019AG10183391Nt1
92034Full Overhaul KRV1025618 36-SV-1623B 8.75 6x1012/08/2019AG10183391Ot10.5
92034Full Overhaul KRV1025618 36-SV-1623B 8.75 6x1012/08/2019AG10183391Ot22
92034Full Overhaul KRV1025618 36-SV-1623B 8.75 6x1012/08/2019AG10183391Ot33
92034Full Overhaul KRV1025618 36-SV-1623B 8.75 6x1012/08/2019AG10183391Ot40.5
92034Full Overhaul KRV1025618 36-SV-1623B 8.75 6x1012/08/2019AG10183391Ns1

<tbody>
</tbody>

Is this even achievable?

Basically for each row in a set of Data I need copies of that in another Worksheet "per rate". So if the data set for example had 10 Rows with 6 different rates....it would transpose into 60 rows of one rate per row.

Messy and I've argued the case for changing the output of the report, but it's what the customer wants.

Anyone seen anything like this?

Thanks in advance,
Kevin
 

Excel Facts

How to fill five years of quarters?
Type 1Q-2023 in a cell. Grab the fill handle and drag down or right. After 4Q-2023, Excel will jump to 1Q-2024. Dash can be any character.
Hi & welcome to MrExcel.
How about
Code:
Sub gimmick18()
   Dim Ary As Variant, Nary As Variant
   Dim r As Long, c As Long, nr As Long, i As Long
   
   Ary = Sheets("Sheet1").Range("A1").CurrentRegion.Value2
   ReDim Nary(1 To UBound(Ary) * (UBound(Ary, 2) - 4), 1 To 6)
   For r = 2 To UBound(Ary)
      For c = 5 To UBound(Ary, 2)
         nr = nr + 1
         For i = 1 To 4
            Nary(nr, i) = Ary(r, i)
         Next i
         Nary(nr, 5) = Ary(1, c)
         Nary(nr, 6) = Ary(r, c)
      Next c
   Next r
   Sheets("Sheet2").Range("A2").Resize(nr, 6).Value = Nary
End Sub
 
Upvote 0
Try this for results on Sheet2.
Code:
[COLOR="Navy"]Sub[/COLOR] MG14Aug13
[COLOR="Navy"]Dim[/COLOR] Ray, n [COLOR="Navy"]As[/COLOR] [COLOR="Navy"]Long,[/COLOR] Ac [COLOR="Navy"]As[/COLOR] [COLOR="Navy"]Long,[/COLOR] c [COLOR="Navy"]As[/COLOR] [COLOR="Navy"]Long,[/COLOR] rw [COLOR="Navy"]As[/COLOR] [COLOR="Navy"]Long[/COLOR]
Ray = ActiveSheet.Range("A1").CurrentRegion
ReDim nray(1 To UBound(Ray, 1) * 6, 1 To 6)
nray(1, 1) = "Wo No": nray(1, 2) = "Directive": nray(1, 3) = "Actual Completion"
nray(1, 4) = "Reference No": nray(1, 5) = "Rate": nray(1, 6) = "Hours"

c = 1
[COLOR="Navy"]For[/COLOR] n = 2 To UBound(Ray, 1)
   [COLOR="Navy"]For[/COLOR] rw = 5 To 10
     c = c + 1
      [COLOR="Navy"]For[/COLOR] Ac = 1 To 4: nray(c, Ac) = Ray(n, Ac): [COLOR="Navy"]Next[/COLOR] Ac
        nray(c, 5) = Ray(1, rw)
          nray(c, 6) = Ray(n, rw)
   [COLOR="Navy"]Next[/COLOR] rw
[COLOR="Navy"]Next[/COLOR] n
[COLOR="Navy"]With[/COLOR] Sheets("Sheet2").Range("A1").Resize(c, 6)
    .Value = nray
    .Borders.Weight = 2
    .Columns.AutoFit
[COLOR="Navy"]End[/COLOR] With
[COLOR="Navy"]End[/COLOR] [COLOR="Navy"]Sub[/COLOR]
Regards Mick
 
Upvote 0
Wow, an absolutely fantastic solution. Efficient, fast and not processor heavy. Thank you so much Fluff, very much appreciated. Got everything going now including reformatting of the output data.
 
Upvote 0
You're welcome & thanks for the feedback
 
Upvote 0

Forum statistics

Threads
1,216,028
Messages
6,128,399
Members
449,447
Latest member
M V Arun

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