How do I change the format?

uwish7

New Member
Joined
Jul 26, 2017
Messages
26
Is there an easy way to change this. Currently my data is in the following format: PartNumber Description Jan Feb Mar ETC. The forecast is under each month currently. I will prefer to have the data like the format below PartNumber Month Description Forecast.
 

Excel Facts

How to find 2nd largest value in a column?
MAX finds the largest value. =LARGE(A:A,2) will find the second largest. =SMALL(A:A,3) will find the third smallest
How many months are there in all? Is it 12?
Does every part number have a value for every month?
 
Upvote 0
Assuming that your header row is row 1, and your data starts in column A, I think this will do what you want:
Code:
Sub MyCopy()

    Dim ws1 As Worksheet, ws2 As Worksheet
    Dim lr As Long, r As Long, nr As Long
    Dim lc As Long, c As Long

    Application.ScreenUpdating = False

'   Set sheet where data currently resides
    Set ws1 = Sheets("Sheet1")
'   Set sheet where to paste results
    Set ws2 = Sheets("Sheet2")
    
'   Find last with data on data sheet
    lr = ws1.Cells(Rows.Count, "A").End(xlUp).Row
    
'   Find last column with data in header row
    lc = ws1.Cells(1, Columns.Count).End(xlToLeft).Column
    
'   Determine number of months (by subtracting 2)
    c = lc - 2

'   Loop through data on data sheet
    For r = 2 To lr
        ws2.Activate
'       Determine next row to paste data to
        nr = ws2.Cells(Rows.Count, "A").End(xlUp).Row + 1
'       Populate part number
        ws2.Range(Cells(nr, "A"), Cells(nr + c - 1, "A")) = ws1.Cells(r, "A")
'       Populate description
        ws2.Range(Cells(nr, "B"), Cells(nr + c - 1, "B")) = ws1.Cells(r, "B")
'       Copy months
        ws1.Activate
        ws1.Range(Cells(1, 3), Cells(1, lc)).Copy
        ws2.Activate
        ws2.Cells(nr, "C").PasteSpecial Paste:=xlPasteAll, Operation:=xlNone, SkipBlanks:= _
            False, Transpose:=True
'       Copy forecast
        ws1.Activate
        ws1.Range(Cells(r, 3), Cells(r, lc)).Copy
        ws2.Activate
        ws2.Cells(nr, "D").PasteSpecial Paste:=xlPasteAll, Operation:=xlNone, SkipBlanks:= _
            False, Transpose:=True
    Next r

    Application.ScreenUpdating = True

    MsgBox "Done!"

End Sub
Just adjust the sheet names for ws1 and ws2 at the top of the code to match your set-up.
 
Last edited:
Upvote 0

Forum statistics

Threads
1,224,823
Messages
6,181,178
Members
453,021
Latest member
Justyna P

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