VBA Translate Column Data into Rows

tryingmybest418

New Member
Joined
Jan 22, 2018
Messages
32
I have a column of information and would like to find a way to translate it into rows using VBA. Every 3-7 rows in my existing column has a cell "New Record". I'd like the information below that cell to be laid out in a new row.

Currently:
New Record
4756
John Doe
123 Street Ave.
Chicago, Illinois
451002
481002
New Record
4869
Jane Doe
0
0
New Record
5012
Jim Thompson
456 Street Ave.
New York, New York
451005
481005

<tbody>
</tbody>

Would Like:
New Record4756John Doe123 Street Ave.Chicago, Illinois451002481002
New Record4869Jane Doe00
New Record5012Jim Thompson456 Street Ave.New York, New York451005481005

<tbody>
</tbody>

Thank you!
 

Excel Facts

Lock one reference in a formula
Need 1 part of a formula to always point to the same range? use $ signs: $V$2:$Z$99 will always point to V2:Z99, even after copying
Code:
Sub tryingmybest418()
Dim A As Range
With Range("A1:A" & Range("A" & Rows.Count).End(xlUp).Row)
    .Replace "New Record", "", xlWhole, xlByRows
    For Each A In .SpecialCells(xlCellTypeConstants).Areas
        With Range("B" & Rows.Count).End(xlUp).Offset(1).Resize(, A.Rows.Count)
            .Value = Application.Transpose(A.Value)
            A.ClearContents
            .Offset(, -1).Resize(1, 1).Value = "New Record"
        End With
    Next A
End With
End Sub
 
Upvote 0
That's it! Thank you so much.

Can I ask if there's a clean way to do this and remove the "New Record" column?

I recorded this and would add it to the end of the code you provided, but am curious if you think there's a better way?

Code:
Sub DeleteNewRecord()


    Columns("A:A").Select
    Selection.Delete Shift:=xlToLeft
End Sub
 
Upvote 0
That's it! Thank you so much.

Can I ask if there's a clean way to do this and remove the "New Record" column?

I recorded this and would add it to the end of the code you provided, but am curious if you think there's a better way?

Code:
Sub DeleteNewRecord()


    Columns("A:A").Select
    Selection.Delete Shift:=xlToLeft
End Sub

maybe try to remove the below line and see if it works for you?

remove:
.Offset(, -1).Resize(1, 1).Value = "New Record"
 
Upvote 0

Forum statistics

Threads
1,214,520
Messages
6,120,011
Members
448,935
Latest member
ijat

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