sort columns remove data from cells reformat numbers

exceltime

New Member
Joined
Aug 19, 2014
Messages
29
I have a spreadsheet of 16 columns. I have written a macro that does the following: Do a text search on the columns I, J, K. Filter the result using criteria colG => Montant2 and colG <= Montant1. Montant1 and 2 are input by the user. Then write the results in a new sheet as colB to colB, colD to colC, colF to colD, colG to colE. Sort the result based on colD , colC in that order, remove duplicates that have colD and colC equal. Format the number field in colE as "#.###0.00".
I have done the text search and filtering. When it came to sort, remove and reformat it does not give any errors but does nothing. Here is the relevant code. To reformat the number field in new sheet colE:

Code:
Worksheets(tName).Activate
Worksheets(tName).Columns("E").ColumnWidth = 15
    Worksheets(tName).Columns("E").NumberFormat = "#,###0.00"

To remove duplicates I tried:
Code:
ActiveSheet.[A1].CurrentRegion.RemoveDuplicates Columns:=5, Header:=xlYes

Also I tried:
Code:
JMAX = Sheets(tName).Cells(Rows.Count, "B").End(xlUp).Row    StartRow = 2
    LastRow = JMAX
    Let CopyRange = "A" & StartRow & ":" & "E" & LastRow
     ActiveSheet.Sort.SortFields.Add Range(CopyRange), xlSortOnValues, xlAscending

and this:
Code:
ActiveSheet.[A1].CurrentRegion.RemoveDuplicates Columns:=5, Header:=xlYes

Any help is highly appreciated.
 

Excel Facts

Return population for a City
If you have a list of cities in A2:A100, use Data, Geography. Then =A2.Population and copy down.

Forum statistics

Threads
1,214,929
Messages
6,122,317
Members
449,081
Latest member
tanurai

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