Format Excel data

jike_s

New Member
Joined
Oct 23, 2006
Messages
5
Hi all-

I wanted to reformat my data from this:

Item Qty 1-Jan 8-Jan 15-Jan 22-Jan
ABC1 1000 77 77 77 77
ABC2 500 38 38 38 38
ABC3 10000 769 769 769 769

to this:

Item Date Qty
ABC1 1-Jan 77
ABC1 8-Jan 77
ABC1 15-Jan 77
ABC1 22-Jan 77
ABC2 1-Jan 38
ABC2 8-Jan 38
ABC2 15-Jan 38
ABC2 22-Jan 38
ABC3 1-Jan 769
ABC3 8-Jan 769
ABC3 15-Jan 769
ABC3 22-Jan 769

I'll appreciate any help on this.

thanks.
 

Excel Facts

VLOOKUP to Left?
Use =VLOOKUP(A2,CHOOSE({1,2},$Z$1:$Z$99,$Y$1:$Y$99),2,False) to lookup Y values to left of Z values.
Hi

This assumes that the data is in column A:F and the output is able to go into columns H:J.

Code:
Sub ddd()
  Range("H1:J1").Value = Array("Item", "Date", "Qty")
  For Each ce In Range("A2:A" & Cells(Rows.Count, 1).End(xlUp).Row)
    For i = 3 To 6
      nextrow = Cells(Rows.Count, 8).End(xlUp).Offset(1, 0).Row
      Cells(nextrow, 8).Value = ce.Value
      Cells(nextrow, 9).Value = Cells(1, i).Value
      Cells(nextrow, 10).Value = Cells(ce.Row, i).Value
    Next i
  Next ce
End Sub


HTH

Tony
 
Upvote 0
Thank you.

What if I want the output on a different sheet? Basically, I want to reformat sheet 1 and have the output on sheet 2. Thanks again.
 
Upvote 0
Hi

Try this.

Code:
Sub ddd()
  Dim OutSh As Worksheet
  Set OutSh = Sheets("Sheet2")
  Sheets("sheet1").Select
  OutSh.Range("A1:C1").Value = Array("Item", "Date", "Qty")
  For Each ce In Range("A2:A" & Cells(Rows.Count, 1).End(xlUp).Row)
    For i = 3 To 6
      With OutSh
        nextrow = .Cells(Rows.Count, 1).End(xlUp).Offset(1, 0).Row
        .Cells(nextrow, 1).Value = ce.Value
        .Cells(nextrow, 2).Value = Cells(1, i).Value
        .Cells(nextrow, 3).Value = Cells(ce.Row, i).Value
      End With
    Next i
  Next ce
End Sub

It assumes that sheet2 exists.

Tony
 
Upvote 0

Forum statistics

Threads
1,214,793
Messages
6,121,614
Members
449,039
Latest member
Mbone Mathonsi

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