Help with Transposing

GoranH

New Member
Joined
May 15, 2019
Messages
8
Here's an example:

Johnapple
Johnfridge
Johnheart
Johnpear
Johncar
Stevensoap
Stevendisplay
Stevenpen
Stevenorange
Stevenbee

<tbody>
</tbody>

I would like it to look like,

JohnapplefridgeheartpearCar
Stevensoapdisplaypenorangebee

<tbody>
</tbody>

My sheet is mostly consisting of numbers, and there might be some "" blanks.
Any help (and explanation) would be greatly appreciated,

Regards!
 

Excel Facts

Did you know Excel offers Filter by Selection?
Add the AutoFilter icon to the Quick Access Toolbar. Select a cell containing Apple, click AutoFilter, and you will get all rows with Apple
Try this

Code:
Option Explicit
Dim CurName As String
Dim CurRow As Long
Dim CurCol As Long
Dim ListLoop As Long
Dim LastRowNo As Long


Sub TransposeList()
'Assuming lsts starts at A1
'Output will start at D1


CurRow = 1
CurCol = 4
LastRowNo = ActiveWorkbook.Worksheets("Sheet1").Range("A65536").End(xlUp).Row 'Or 1048576 if sheet has that many rows
CurOK = False
CurName = ""


For ListLoop = 1 To LastRowNo
    If CurName = ActiveWorkbook.Worksheets("Sheet1").Range("A" & ListLoop).Value Then
        CurCol = CurCol + 1
        ActiveWorkbook.Worksheets("Sheet1").Cells(CurRow, CurCol).Value = ActiveWorkbook.Worksheets("Sheet1").Range("B" & ListLoop).Value
    Else
        CurRow = CurRow + 1
        CurCol = 4
        CurName = ActiveWorkbook.Worksheets("Sheet1").Range("A" & ListLoop).Value
        ActiveWorkbook.Worksheets("Sheet1").Cells(CurRow, CurCol).Value = CurName
        CurCol = CurCol + 1
        ActiveWorkbook.Worksheets("Sheet1").Cells(CurRow, CurCol).Value = ActiveWorkbook.Worksheets("Sheet1").Range("B" & ListLoop).Value
    End If
    If CurName = "" Then
        CurName = ActiveWorkbook.Worksheets("Sheet1").Range("A" & ListLoop).Value
        ActiveWorkbook.Worksheets("Sheet1").Cells(CurRow, CurCol).Value = CurName
        CurCol = CurCol + 1
        ActiveWorkbook.Worksheets("Sheet1").Cells(CurRow, CurCol).Value = ActiveWorkbook.Worksheets("Sheet1").Range("B" & ListLoop).Value
    End If
Next ListLoop


End Sub
 
Upvote 0
Try this

Code:
Option Explicit
Dim CurName As String
Dim CurRow As Long
Dim CurCol As Long
Dim ListLoop As Long
Dim LastRowNo As Long


Sub TransposeList()
'Assuming lsts starts at A1
'Output will start at D1


CurRow = 1
CurCol = 4
LastRowNo = ActiveWorkbook.Worksheets("Sheet1").Range("A65536").End(xlUp).Row 'Or 1048576 if sheet has that many rows
CurOK = False
CurName = ""


For ListLoop = 1 To LastRowNo
    If CurName = ActiveWorkbook.Worksheets("Sheet1").Range("A" & ListLoop).Value Then
        CurCol = CurCol + 1
        ActiveWorkbook.Worksheets("Sheet1").Cells(CurRow, CurCol).Value = ActiveWorkbook.Worksheets("Sheet1").Range("B" & ListLoop).Value
    Else
        CurRow = CurRow + 1
        CurCol = 4
        CurName = ActiveWorkbook.Worksheets("Sheet1").Range("A" & ListLoop).Value
        ActiveWorkbook.Worksheets("Sheet1").Cells(CurRow, CurCol).Value = CurName
        CurCol = CurCol + 1
        ActiveWorkbook.Worksheets("Sheet1").Cells(CurRow, CurCol).Value = ActiveWorkbook.Worksheets("Sheet1").Range("B" & ListLoop).Value
    End If
    If CurName = "" Then
        CurName = ActiveWorkbook.Worksheets("Sheet1").Range("A" & ListLoop).Value
        ActiveWorkbook.Worksheets("Sheet1").Cells(CurRow, CurCol).Value = CurName
        CurCol = CurCol + 1
        ActiveWorkbook.Worksheets("Sheet1").Cells(CurRow, CurCol).Value = ActiveWorkbook.Worksheets("Sheet1").Range("B" & ListLoop).Value
    End If
Next ListLoop


End Sub

Hey mate, thanks for the code... I assume it's VBA, and I'm gona run it as a module. But I'm new to this, so further help would be appreciated.
I have column A which is the Johns/Stevens etc. and column B which is the items related to them. There can be blank values in column B.
And it's sheet "Sheet1", spanning from A1:B11053. So 11053 Rows including Header.

At the moment I'm getting "Compile Error - Variable not Defined", and pointing toward "Sub Transpose List". So what do I need to enter/change to make it work?
Regards.
 
Upvote 0
Sorry, my bad. The CurOK = False line is not needed any more.
 
Upvote 0

Forum statistics

Threads
1,215,409
Messages
6,124,733
Members
449,185
Latest member
hopkinsr

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