Transpose data from wide format to long format excel

ipmh35

New Member
Joined
Aug 20, 2021
Messages
4
Office Version
  1. 365
  2. 2019
  3. 2016
Platform
  1. Windows
  2. MacOS
Currently, my excel sheet is composed of data that are not in long format. enter image description here

I want to cut the data to paste at the bottom of the first 2 columns to get something like this:

enter image description here

I have written some vba code to allow me to do the cutting and pasting. However, the code doesn't seem to exit the Find Loop and continuously finds and cuts. I want to stop finding after all columns after the 1st 2 are cut and pasted to the bottom. What edits can I make to the code to allow the find to escape the loop? Thank you

VBA Code:
Sub FindTextInSheets()
    Dim FirstAddress As String
    Dim myColor As Variant
    Dim rng As Range
    Dim Corp As Range
    Dim rowscount As Variant
    Dim rowsno As Integer
                Set rng = ActiveSheet.Cells.Find(What:="Code", _
                                After:=Range("B1"), _
                                LookIn:=xlValues, _
                                LookAt:=xlWhole, _
                                SearchOrder:=xlByColumns, _
                                SearchDirection:=xlNext, _
                                MatchCase:=False)
                If Not rng Is Nothing Then
                    FirstAddress = rng.Address
                    Do
                        rng.Select
                        Range(Selection, Selection.Offset(0, 1)).Select
                        Range(Selection, Selection.End(xlDown)).Select
                        Selection.Cut
                        Range("A1").Select
                        Selection.End(xlDown).Select
                        Selection.Offset(1, 0).Select
                        ActiveSheet.Paste
                        Set rng = ActiveSheet.Cells.FindNext(rng)
                    Loop While Not rng Is Nothing And rng.Address <> FirstAddress
                End If
        
        End Sub
 

Excel Facts

Create a chart in one keystroke
Select the data and press Alt+F1 to insert a default chart. You can change the default chart to any chart type
Do you want the header row copied with the rest of the data?
 
Upvote 0
Ok, how about
VBA Code:
Sub ipmh()
   Dim i As Long
   
   For i = 3 To Cells(1, Columns.Count).End(xlToLeft).Column Step 2
      Range(Cells(2, i), Cells(Rows.Count, i).End(xlUp)).Resize(, 2).Cut Range("A" & Rows.Count).End(xlUp).Offset(1)
   Next i
   Range("C1").Resize(, i + 1).Value = ""
End Sub
 
Upvote 0
Solution
Cross-posting (posting the same question in more than one forum) is not against our rules, but the method of doing so is covered by #13 of the Forum Rules.

Be sure to follow & read the link at the end of the rule too!

Cross posted at: Transferring Wide Data to Long Data
and Transpose data from wide format to long format excel - OzGrid Free Excel/VBA Help Forum

If you have posted the question at more places, please provide links to those as well.

If you do cross-post in the future and also provide links, then there shouldn’t be a problem.
 
Upvote 0
You're welcome & thanks for the feedback.
 
Upvote 0

Forum statistics

Threads
1,224,300
Messages
6,177,754
Members
452,798
Latest member
mlance617

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