VBA - Copy data to new range then sort and remove duplicate

Chowz

New Member
Joined
Apr 7, 2014
Messages
5
I want some example of VBA that could copy data (A1:B15) to new range (D1:E15) then sort and remove duplicate.



SWSCentral Pinklao FLG RMA TradingThonglor 13
SWSIT SquareSWSCentral Pinklao FLG
SWSIT SquareSWSIT Square
SWSBig C Wongsawang
SWSAyutthaya Park
SWSAyutthaya ParkSWSLotus Srinagarindra
SWSThe Mall 5 Thapra
SWSBig C Wongsawang
SWSLotus Srinagarindra
SWSLotus Srinagarindra
RMA TradingThonglor 13
SWSThe Mall 5 Thapra

<tbody>
</tbody>

<colgroup><col><col span="2"><col><col></colgroup><tbody>
</tbody>

Thank you for every helps.
 

Excel Facts

Shade all formula cells
To shade all formula cells: Home, Find & Select, Formulas to select all formulas. Then apply a light fill color.
Chowz,

Sample raw data:


Excel 2007
ABCDE
1SWSCentral Pinklao FLG
2SWSIT Square
3SWSIT Square
4
5
6SWSAyutthaya Park
7
8SWSBig C Wongsawang
9
10SWSLotus Srinagarindra
11SWSLotus Srinagarindra
12
13RMA TradingThonglor 13
14
15SWSThe Mall 5 Thapra
16
Sheet1


After the macro:


Excel 2007
ABCDE
1SWSCentral Pinklao FLGRMA TradingThonglor 13
2SWSIT SquareSWSAyutthaya Park
3SWSIT SquareSWSBig C Wongsawang
4SWSCentral Pinklao FLG
5SWSIT Square
6SWSAyutthaya ParkSWSLotus Srinagarindra
7SWSThe Mall 5 Thapra
8SWSBig C Wongsawang
9
10SWSLotus Srinagarindra
11SWSLotus Srinagarindra
12
13RMA TradingThonglor 13
14
15SWSThe Mall 5 Thapra
16
Sheet1


Please TEST this FIRST in a COPY of your workbook (always make a backup copy before trying new code, you never know what you might lose).

1. Copy the below code
2. Open your NEW workbook
3. Press the keys ALT + F11 to open the Visual Basic Editor
4. Press the keys ALT + I to activate the Insert menu
5. Press M to insert a Standard Module
6. Where the cursor is flashing, paste the code
7. Press the keys ALT + Q to exit the Editor, and return to Excel
8. To run the macro from Excel press ALT + F8 to display the Run Macro Dialog. Double Click the macro's name to Run it.

Code:
Sub RemoveDupesSort()
' hiker95, 07/04/2014, ME789286
Dim lr As Long
Application.ScreenUpdating = False
Columns("D:E").ClearContents
Rows(1).Insert
Cells(1, 1).Resize(, 2).Value = Array("A", "B")
Columns("A:B").AdvancedFilter Action:=xlFilterCopy, CopyToRange:=Columns("D:E"), Unique:=True
Rows(1).Delete
lr = Cells(Rows.Count, "D").End(xlUp).Row
Range("D1:E" & lr).SpecialCells(xlCellTypeBlanks).Delete Shift:=xlUp
lr = Cells(Rows.Count, "D").End(xlUp).Row
Range("D1:E" & lr).Sort key1:=Range("D1"), order1:=1, key2:=Range("E1"), order1:=1
Columns("D:E").AutoFit
Application.ScreenUpdating = True
End Sub

Before you use the macro with Excel 2007 or newer, save your workbook, Save As, a macro enabled workbook with the file extension .xlsm

Then run the RemoveDupesSort macro.
 
Upvote 0

Forum statistics

Threads
1,215,473
Messages
6,125,018
Members
449,203
Latest member
tungnmqn90

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