Create 1 new list from 4 changing length columns

billybowen

New Member
Joined
Apr 21, 2018
Messages
2
Hi all, i have 4 equal columns of names A-D and in E i have the number of rows with names in the columns which changes, im looking to create a new list in F containing all 4 columns names without spaces accounting for the length of column changes, help much appreciated.
 

Excel Facts

Excel Wisdom
Using a mouse in Excel is the work equivalent of wearing a lanyard when you first get to college
Code:
Sub DoIt()
    Dim LastRow As Long
    Dim LastRowB As Long
    LastRow = ActiveSheet.Cells(ActiveSheet.Rows.Count, "A").End(xlUp).Row
    LastRowB = ActiveSheet.Cells(ActiveSheet.Rows.Count, "E").End(xlUp).Row
    ActiveSheet.Range("A2:A" & LastRow).Copy Destination:=ActiveSheet.Range("E2")
    LastRow = ActiveSheet.Cells(ActiveSheet.Rows.Count, "B").End(xlUp).Row
    LastRowB = ActiveSheet.Cells(ActiveSheet.Rows.Count, "E").End(xlUp).Row
    ActiveSheet.Range("B2:B" & LastRow).Copy Destination:=ActiveSheet.Range("E" & LastRowB + 1)
    LastRow = ActiveSheet.Cells(ActiveSheet.Rows.Count, "C").End(xlUp).Row
    LastRowB = ActiveSheet.Cells(ActiveSheet.Rows.Count, "E").End(xlUp).Row
    ActiveSheet.Range("C2:C" & LastRow).Copy Destination:=ActiveSheet.Range("E" & LastRowB + 1)
    LastRow = ActiveSheet.Cells(ActiveSheet.Rows.Count, "D").End(xlUp).Row
    LastRowB = ActiveSheet.Cells(ActiveSheet.Rows.Count, "E").End(xlUp).Row
    ActiveSheet.Range("D2:D" & LastRow).Copy Destination:=ActiveSheet.Range("E" & LastRowB + 1)
    LastRowB = ActiveSheet.Cells(ActiveSheet.Rows.Count, "E").End(xlUp).Row
    Range("E2:E" & LastRowB).Select
    ActiveSheet.Sort.SortFields.Clear
    ActiveSheet.Sort.SortFields.Add Key:=Range("E2:E" & LastRowB) _
        , SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:=xlSortNormal
    With ActiveWorkbook.Worksheets("Sheet1").Sort
        .SetRange Range("E2:E" & LastRowB)
        .Header = xlGuess
        .MatchCase = False
        .Orientation = xlTopToBottom
        .SortMethod = xlPinYin
        .Apply
    End With
End Sub
 
Upvote 0

Forum statistics

Threads
1,224,823
Messages
6,181,181
Members
453,022
Latest member
Mohamed Magdi Tawfiq Emam

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