Transpose macro varying rows from 1 column

tommyleinen

Board Regular
Joined
Aug 22, 2009
Messages
74
I've trawled a few forums for a while now trying to find a macro that matches my specifications, or one I can adapt but so far have been unsuccessful, so here goes:

I have one column of data (col. A) of customer names and addresses each with an empty row in between them. The lines of data relating to each customer vary from 6 rows to 14 rows, then an empty row, then the next customer and so on - for several thousand rows.

I am wanting to create a macro that will transpose each customer to either their own row in sheet2, or to column B and then delete column A at the end.

All I can find is macros for a specific number of rows rather than varying. One way would be to have a code that 'pads' out those customers with fewer than 14 lines by inserting rows to make them 14, and then a code to transpose 15 rows at a time.

There are maybe a number of ways to do this but my limited knowledge leaves me with none at the moment. Hopefully some talented person out there can help? :confused:
 
Actually if you were to assume ascii 160 is the culprit, which it often is, a one-liner would do instead of all that:

Columns(1).Replace what:=Chr(160), Replacement:=""
 
Upvote 0

Excel Facts

Using Function Arguments with nested formulas
If writing INDEX in Func. Arguments, type MATCH(. Use the mouse to click inside MATCH in the formula bar. Dialog switches to MATCH.
The more details you provide, the better as a rule of thumb.

This you just wrote is important:
"The number of lines in my sheet is close to 130,000. Do you think this might be a factor?"

I used specialcells which has a per-iteration collection maximum of 8192 ranges. That does not necessarily mean that 130,000 rows will exceed the 8192 number, because the 8192 number depends on sets of data (areas), not the total rows. So, for example if the average count of cells in your 130,000 rows is, say 10, then that would be 13,000 areas and would exceed the 8192 number. Additional code for sets of areas would be needed if that is what we are indeed dealing with.
 
Upvote 0
Try this variation for starters, and with all those rows a little patience will be needed but I think this works or comes close enough for a test run:

Code:
Sub SonOfTranspozeRowz()
With Application
.ScreenUpdating = False
.DisplayAlerts = False
Dim asn$, xRow&, iCol%, xCounter&, LastRow&
Dim cell As Range, area As Range
LastRow = Cells(Rows.Count, 1).End(xlUp).Row
asn = ActiveSheet.Name
xCounter = 1
On Error Resume Next
Sheets("zzzTranspozed").Delete
Err.Clear
Sheets.Add(After:=Sheets(Sheets.Count)).Name = "zzzTranspozed"
xRow = 1
With Sheets(asn)
Do
For Each area In .Range(.Cells(xCounter, 1), .Cells(xCounter + 10000, 1)).SpecialCells(2).Areas
iCol = 1
For Each cell In area
cell.Copy Cells(xRow, iCol)
iCol = iCol + 1
Next cell
xRow = xRow + 1
Next area
xCounter = xCounter + 10001
Loop While xCounter <= LastRow
End With

Columns.AutoFit
.DisplayAlerts = True
.ScreenUpdating = True
End With
End Sub
 
Upvote 0

Forum statistics

Threads
1,221,417
Messages
6,159,789
Members
451,589
Latest member
Harold14

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