Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Junior Member
 
Posts: 1
Default Suffule data to rearrange in specified format

Hi ,

I have data in this format

Prod_code product jan feb mar
x1 xxx 23 32 34
y1 yyy 45 45 45
z1 zzz 89 89 89

and i need to convert the data in the below format

prod_code product month value
x1 xxx jan 23
y1 yyy jan 45
z1 zzz jan 89
x1 xxx feb 32
y1 yyy feb 45
z1 zzz feb 89
x1 xxx mar 34
y1 yyy mar 45
z1 zzz mar 89

Please help me in write a macro ......
  #2   Report Post  
Member
 
Posts: 31
Default

Quote:
Originally Posted by januprasad View Post
Hi ,

I have data in this format

Prod_code product jan feb mar
x1 xxx 23 32 34
y1 yyy 45 45 45
z1 zzz 89 89 89

and i need to convert the data in the below format

prod_code product month value
x1 xxx jan 23
y1 yyy jan 45
z1 zzz jan 89
x1 xxx feb 32
y1 yyy feb 45
z1 zzz feb 89
x1 xxx mar 34
y1 yyy mar 45
z1 zzz mar 89

Please help me in write a macro ......
Try this macro. The comments in the code should explain what is going on and allow you to modify it as suits.

Sub ReSortData()
Range("C1").Activate 'Assumes this is where Jan is
WriteToRow = 20 'This is how many rows down you want to start writing the data
Do While ActiveCell.Offset(1, 0) < "" 'Loop for every product row until a blank found
ProductRow = 1 'Holds the row to currently read
Do While ActiveCell.Offset(ProductRow, 0) < "" 'Loop for each Month across until a blank found
ActiveCell.Offset(WriteToRow, 0 - (ActiveCell.Column - 1)) = ActiveCell.Offset(ProductRow, 0 - (ActiveCell.Column - 1))
ActiveCell.Offset(WriteToRow, 0 - (ActiveCell.Column - 2)) = ActiveCell.Offset(ProductRow, 0 - (ActiveCell.Column - 2))
ActiveCell.Offset(WriteToRow, 0 - (ActiveCell.Column - 3)) = ActiveCell
ActiveCell.Offset(WriteToRow, 0 - (ActiveCell.Column - 4)) = ActiveCell.Offset(ProductRow, 0)
ProductRow = ProductRow + 1
WriteToRow = WriteToRow + 1
Loop
ActiveCell.Offset(0, 1).Activate
Loop
End Sub

Please excuse the lack of formatting - I'll work out how to do that one day. Just copy & paste the above as a new macro and adjust the variables as necessary and it should work. Give me a shout if any problems.
Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
rearrange the data with a new table KS Excel Worksheet Functions 6 February 18th 09 02:16 PM
Rearrange data in columns Alvarez Excel Discussion (Misc queries) 4 October 7th 08 08:32 AM
How to rearrange data... Eric Charts and Charting in Excel 1 January 10th 07 10:31 PM
rearrange data chartasap Excel Discussion (Misc queries) 4 May 1st 06 04:44 PM
rearrange data by day Adent Excel Discussion (Misc queries) 4 July 31st 05 09:26 PM


All times are GMT +1. The time now is 07:31 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"