Macro to combine and sort column data

guybrownbarnett

New Member
Joined
Oct 2, 2013
Messages
4
Hi all

I wonder if anyone can help me create a macro.
Essentially, I'm looking to populate an empty column with alphabetically sorted combined data from 2 existing columns, then add data below from a third column.



For example:
Sheet2 ColumnA is cleared.
All populated cells in Sheet1 ColumnA are copied into Sheet2 ColumnA.
All populated cells in Sheet1 ColumnB are copied into Sheet2 ColumnA below any existing data.
Sheet2 ColumnA is sorted alphabetically.
All populated cells in Sheet1 ColumnC are copied into Sheet2 ColumnA below any existing data.

Any ideas much appreciated?

Regards,

Guy Brown
 

Excel Facts

Who is Mr Spreadsheet?
Author John Walkenbach was Mr Spreadsheet until his retirement in June 2019.
Dim lastrow As Long
lastrow = Cells(Rows.Count, "a").End(xlUp).Row

Sheets("Sheet2").Select
Columns("A:A").ClearContents

Sheets("Sheet1").Select
Range("A1:a" & lastrow).Copy
Sheets("Sheet2").Select
Range("a1").Select
ActiveSheet.Paste
Sheets("Sheet1").Select
lastrow = Cells(Rows.Count, "b").End(xlUp).Row
Range("b1:b" & lastrow).Copy
Sheets("Sheet2").Select
lastrow = Cells(Rows.Count, "a").End(xlUp).Row
Range("a" & lastrow + 1).Select
ActiveSheet.Paste
lastrow = Cells(Rows.Count, "a").End(xlUp).Row

With ActiveWorkbook.Worksheets("Sheet2").Sort
.SetRange Range("A1:A" & lastrow)
.Header = xlGuess
.MatchCase = False
.Orientation = xlTopToBottom
.SortMethod = xlPinYin
.Apply
End With
Sheets("Sheet1").Select
lastrow = Cells(Rows.Count, "c").End(xlUp).Row
Range("c1:c" & lastrow).Copy
Sheets("Sheet2").Select
lastrow = Cells(Rows.Count, "a").End(xlUp).Row
Range("a" & lastrow + 1).Select
ActiveSheet.Paste
 
Upvote 0
Dim lastrow As Long
lastrow = Cells(Rows.Count, "a").End(xlUp).Row

Sheets("Sheet2").Select
Columns("A:A").ClearContents

Sheets("Sheet1").Select
Range("A1:a" & lastrow).Copy
Sheets("Sheet2").Select
Range("a1").Select
ActiveSheet.Paste
Sheets("Sheet1").Select
lastrow = Cells(Rows.Count, "b").End(xlUp).Row
Range("b1:b" & lastrow).Copy
Sheets("Sheet2").Select
lastrow = Cells(Rows.Count, "a").End(xlUp).Row
Range("a" & lastrow + 1).Select
ActiveSheet.Paste
lastrow = Cells(Rows.Count, "a").End(xlUp).Row

With ActiveWorkbook.Worksheets("Sheet2").Sort
.SetRange Range("A1:A" & lastrow)
.Header = xlGuess
.MatchCase = False
.Orientation = xlTopToBottom
.SortMethod = xlPinYin
.Apply
End With
Sheets("Sheet1").Select
lastrow = Cells(Rows.Count, "c").End(xlUp).Row
Range("c1:c" & lastrow).Copy
Sheets("Sheet2").Select
lastrow = Cells(Rows.Count, "a").End(xlUp).Row
Range("a" & lastrow + 1).Select
ActiveSheet.Paste


Thank you very much! I'm on my way. Appreciate that. Regards, Guy
 
Upvote 0

Forum statistics

Threads
1,223,911
Messages
6,175,325
Members
452,635
Latest member
laura12345

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