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

Select all contiguous cells
Pressing Ctrl+* (asterisk) will select the "current region" - all contiguous cells in all directions.
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,223,905
Messages
6,175,297
Members
452,633
Latest member
DougMo

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