Transpose single column into multiple rows based on criteria

farisi

New Member
Joined
May 25, 2023
Messages
5
Office Version
  1. 365
Platform
  1. Windows
Hi,
I would like to transpose a single column into multiple rows based on 2 criteria:
1. If "name" change the letter, it will create new row
2. If each "name" have more than 5 "node", it will create new row

Input:
Picture1.png


Output:
Picture2.png


Any help/advice will be very appreciated. Thanks
 

Excel Facts

What does custom number format of ;;; mean?
Three semi-colons will hide the value in the cell. Although most people use white font instead.
Hello @farisi
Welcome to the MrExcel forum. Please accept my warmest greetings and sincere hope that all is well.

Try this macro:
VBA Code:
Sub TransposeColumn()
  Dim i As Long, j As Long
  Dim c As Range, f As Range
  Range("D:J").ClearContents
  For Each c In Range("A2", Range("A" & Rows.Count).End(3))
    Set f = Range("D:D").Find(c.Value, , xlValues, xlWhole, xlByRows, xlPrevious)
    If f Is Nothing Then
      Range("D" & Rows.Count).End(3)(2).Resize(1, 2).Value = c.Resize(1, 2).Value
    Else
      j = Cells(f.Row, Columns.Count).End(1).Column
      If j = Columns("I").Column Then
        Range("D" & Rows.Count).End(3)(2).Resize(1, 2).Value = c.Resize(1, 2).Value
      Else
        Cells(f.Row, j + 1).Value = c.Offset(0, 1).Value
      End If
    End If
  Next
End Sub

The results as shown in the image below.
Dante Amor
ABCDEFGHI
1NameNodeNameNodeNodeNodeNodeNode
2A1A12345
3A2A67
4A3B89101112
5A4B1314
6A5C151617
7A6
8A7
9B8
10B9
11B10
12B11
13B12
14B13
15B14
16C15
17C16
18C17
Hoja2



HOW TO INSTALL MACROs
------------------------------------
If you are new to macros, they are easy to install and use. To install it, simply press ALT+F11 to go into the VB editor and, once there, click Insert/Module on its menu bar, then copy/paste the above code into the code window that just opened up. That's it.... you are done. To use the macro, go back to the worksheet with your data on it and press ALT+F8, select the macro name (FixAndSplitApartRecords) from the list that appears and click the Run button. The macro will execute and perform the action(s) you asked for. If you will need to do this again in this same workbook, and if you are using XL2007 or above, make sure you save your file as an "Excel Macro-Enabled Workbook (*.xlsm) and answer the "do you want to enable macros" question as "Yes" or "OK" (depending on the button label for your version of Excel) the next time you open your workbook.


--------------
Let me know the result and I'll get back to you as soon as I can.
Cordially
Dante Amor
--------------​
 
Upvote 1
Solution
Hi, thank you so much for your warmth welcome and your solution, it works like a charm.
I really appreciate it, thanks man....
 
Upvote 0

Forum statistics

Threads
1,223,885
Messages
6,175,186
Members
452,615
Latest member
bogeys2birdies

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