Help create simple macro

Richlard

New Member
Joined
Feb 22, 2021
Messages
3
Office Version
  1. 365
Platform
  1. MacOS
Please can anyone create a simple macro to transpose this list of a few hundred names and addresses in column A which are in groups of 4 or 5 rows with blank rows in between, into separate columns? Many thanks.

Screenshot.jpg
 

Excel Facts

Workdays for a market open Mon, Wed, Friday?
Yes! Use "0101011" for the weekend argument in NETWORKDAYS.INTL or WORKDAY.INTL. The 7 digits start on Monday. 1 means it is a weekend.
try this, I have assumed the data in is column A and I have writtein it out to columns B to J
VBA Code:
Sub test()
lastrow = Cells(Rows.Count, "A").End(xlUp).Row
inarr = Range(Cells(1, 1), Cells(lastrow, 1))
Dim outarr()
ReDim outarr(1 To lastrow, 1 To 10)
colno = 1
rowno = 1
blanklast = False
For i = 1 To lastrow
    If inarr(i, 1) = "" Then
        colno = 1
        If Not (blanklast) Then
        rowno = rowno + 1
        blanklast = True
        End If
    Else
    blanklast = False
    outarr(rowno, colno) = inarr(i, 1)
    colno = colno + 1
    End If
Next i
Range(Cells(1, 2), Cells(lastrow, 11)) = outarr

End Sub
 
Upvote 0
Maybe this...note it starts at cell A1
VBA Code:
Sub TransposeAreas()
'original code by Peter_SSs
  Dim aArea As Range, nr As Long
  Application.ScreenUpdating = False
  nr = 2
  For Each aArea In Range("A1", Range("A" & Rows.Count).End(xlUp)).SpecialCells(xlCellTypeConstants).Areas
    aArea.Copy
    Cells(nr, 3).PasteSpecial Transpose:=True
    nr = nr + 1
  Next aArea
  Application.CutCopyMode = False
  Application.ScreenUpdating = True
End Sub
 
Upvote 0
Sorry. It hasn't worked. Got this alert:

Subscript out of range (Error 9)​



try this, I have assumed the data in is column A and I have writtein it out to columns B to J
VBA Code:
Sub test()
lastrow = Cells(Rows.Count, "A").End(xlUp).Row
inarr = Range(Cells(1, 1), Cells(lastrow, 1))
Dim outarr()
ReDim outarr(1 To lastrow, 1 To 10)
colno = 1
rowno = 1
blanklast = False
For i = 1 To lastrow
    If inarr(i, 1) = "" Then
        colno = 1
        If Not (blanklast) Then
        rowno = rowno + 1
        blanklast = True
        End If
    Else
    blanklast = False
    outarr(rowno, colno) = inarr(i, 1)
    colno = colno + 1
    End If
Next i
Range(Cells(1, 2), Cells(lastrow, 11)) = outarr

End Sub
 
Upvote 0
Try
VBA Code:
Sub test()
    Dim ar As Range
    Dim i As Long
    i = 1
  For Each ar In Columns("A:A").SpecialCells(2, 3).Areas
        Cells(i, 3).Resize(, ar.Count) = Application.Transpose(ar)
        i = i + 1
    Next
End Sub
 
Upvote 0

Forum statistics

Threads
1,214,920
Messages
6,122,269
Members
449,075
Latest member
staticfluids

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