Horizontal to Vertical with repeating key fields

SWinfield

New Member
Joined
May 6, 2011
Messages
9
Hi, I hope someone can point me in the right direction as I've hit a brick wall.

I have a file that is laid out horizontally as below;

Unit / Employee Number / OT Rate 1 / OT Rate 1 value / OT Rate 2 / OT Rate 2 Value / and repeat 13 times!

But to be able to load it into our system it needs to be laid out like this;

Unit / Employee Number / OT Rate 1 / OT Rate 1 Value
Unit / Employee Number / OT Rate 2 / OT Rate 2 Value

So i need to change the OT Rate and associated value into vertically held data but duplicate the employee number next to it..

I hope that makes sense?

Any suggestions will be greatfully received!

Thanks

Shaun
 

Excel Facts

Format cells as currency
Select range and press Ctrl+Shift+4 to format cells as currency. (Shift 4 is the $ sign).
Hi there,

  1. Is it OT Rate 1 thru OT Rate 13?
  2. Do we need to worry about blanks?
    1. If yes, do we need to check the Rate or Value to see if empty?
  3. VBA okay?
  4. What column and row starts the data?
 
Upvote 0
Hi GTO,

1. Yes there are 13 different rates to be loaded, so it's OT 1 -> OT13, so what I need to make happen is take the one horizontal line, repeat the unit & employee number 13 times vertically with each individual rate returned against it.

2. There won't be any blank cells to worry about, if no data exists against a rate it will return a 0.

3. VBA is fine by me, I can handle cutting and pasting what I need into VBA - but writing actual code is something I can only do for really basic stuff at the moment!

4. Unit = A1, Employee No = B1, Rate 1 = C1, Value 1 = D1 (continues across 13 rates) So for example the 10th entry down would start from A10. There are no headings, this is an extract from an input sheet.

If it would be easier I'll see if I can get the HTML Excel exporter to work so you can see the actual sheet.

Thanks for having a look!
 
Upvote 0
Ok,

This is the original sheet the data is keyed in on

Excel Workbook
ABCDEFGHIJK
1Overtime
2WorkingHourlyAnnual111.251.331.52
3GroupEmp NoDaysRateSalary83183283483683883C
40857003066521.52741418111111
50857001086511.264521673211111
60857001770530.918360974111111
70907002986511.47622080121111
80857001089519.707937918111111
90857001089519.707937918111111
Input Sheet
Excel Workbook
ABCDEFGHIJKL
10857003066831100832100834100836100838100
Excel 2003 And this is how it looks in the sheet I need to convert Output Test 1
Excel 2003
 
Upvote 0
Thank you. I think I am 'getting' part of it, as I see where the 831, 832,...,838 is coming from. The vals (100 is the one row shown) in D/F/H..., are getting converted to 1's and in a couple of cases 2's?

Sorry if I am being thick-headed, but that part is throwing me a bit. Could you show a few rows of raw data? I am guessing:
Excel Workbook
ABCDEFGHIJKL
1857003066831100832100834100836100838100
2857001086831100832100834100836100838100
3857001770831100832100834100836100838100
4907002986831100832100834100836100838100
5857001089831100832100834100836100838100
6857001089831100832100834100836100838100
Sheet1
Excel 2003
 
Upvote 0
Hi GTO,

1. Yes there are 13 different rates to be loaded, so it's OT 1 -> OT13, so what I need to make happen is take the one horizontal line, repeat the unit & employee number 13 times vertically with each individual rate returned against it.

I think I am misunderstanding post 4, as I thought the top example was output. Leastwise if ea emp ID# is to be run down 13 times as stated above.
 
Upvote 0
Hi GTO,

You don't really need to worry about the first Excel sheet, that's where the data is keyed in by numerous people. So it's formated to be easier to read for them.

What I currently have is this;

Excel Workbook
ABCDEFGH
1085700501831183228333
2085700502831383228331
3085700503831483258336
4085700504831183288332
Original
Excel Workbook
ABCD
10857005018311
20857005018322
30857005018333
40857005028313
50857005028322
60857005028331
70857005038314
80857005038325
90857005038336
100857005048311
110857005048328
120857005048332
Excel 2003 But I need to automate the conversion of it into this Required Format
Excel 2003



Hope that clarifies!
 
Upvote 0
Okay, in a junk copy of your wb, with the raw data in Sheet1, see if this is in the right direction.
Rich (BB code):
Option Explicit
    
Sub exa()
'(If Group Number and/or Emp ID can be counted on as numbers, change to As Long         //
Dim _
aryInput        As Variant, _
aryOutput       As Variant, _
GroupNum        As Variant, _
EmpID           As Variant, _
lLRow           As Long, _
i               As Long, _
ii              As Long, _
n               As Long
    
    '// Using Codenames of the sheets.  'Sheet1' (or that is, the Codename of the sheet //
    '// the raw data) to be transferred to Sheet2 (codename of a blank sheet) to see    //
    '// if I am in the direction you want to be going...                                //
    With Sheet1
        '// Find last EmpID                                                             //
        lLRow = .Cells(.Rows.Count, "B").End(xlUp).Row
        
        '// Size output array                                                           //
        ReDim aryOutput(1 To lLRow * 13, 1 To 4)
        '// Grab raw vals                                                               //
        aryInput = Range(.Range("A1"), .Cells(lLRow, 28)).Value
        
        '// For ea row...                                                               //
        For i = 1 To lLRow
            '// ...save the group num and ID to keep plunking into Output array...      //
            GroupNum = aryInput(i, 1)
            EmpID = aryInput(i, 2)
            '// Loop thru the columns in the row.                                       //
            For ii = 3 To 27 Step 2
                n = n + 1
                aryOutput(n, 1) = GroupNum
                aryOutput(n, 2) = EmpID
                aryOutput(n, 3) = aryInput(i, ii)
                aryOutput(n, 4) = aryInput(i, ii + 1)
            Next
        Next
    End With
    '// Plunk outout wherever.                                                          //
    Sheet2.Range("A1").Resize(UBound(aryOutput, 1), 4).Value = aryOutput
End Sub
Hope that helps,

Mark
 
Upvote 0

Forum statistics

Threads
1,224,609
Messages
6,179,881
Members
452,948
Latest member
Dupuhini

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