Remove duplicates keep formatting

Aqusmacro

New Member
Joined
Jan 8, 2024
Messages
46
Office Version
  1. 2013
Platform
  1. Windows
Hi I have tried many remove duplicates I found but all remove the formatting.
I did add a vba code to copy paste formatting but sometimes does not work and gives me error
Is there a way to remove duplicates and keep formatting?

Here are two I am trying to use but on this one getting Run time error 1004
Pastespecial method of range class failed

VBA Code:
ActiveSheet.Range("A:l").RemoveDuplicates Columns:=Array(1, 2, 4, 9, 10), Header:=xlYes
    ActiveSheet.Range("A:l").Copy
     ActiveSheet.Range("A:l").PasteSpecial xlPasteFormat
    ActiveSheet.Range("A:l").PasteSpecial xlPasteValidation

2nd I was using and was working great until yesterday I imported a new CSV file and then stopped.
I removed the
'Dim lastRow As Long
'Dim lastCol As Long
and started working again, then today imported new csv file and getting error run time 1004
Application defined or object defined error
here is the second

VBA Code:
  'Dim lastRow As Long
    'Dim lastCol As Long
 
    lastRow = Cells(Rows.Count, "A").End(xlUp).Row
    lastCol = Cells.Find("*", SearchOrder:=xlByRows, SearchDirection:=xlPrevious)
    
    Range(Cells(1, 1), Cells(lastRow, lastCol)).RemoveDuplicates Columns:=Array(1, 2, 4, 9, 10)
       

     Sheets("transactions").Range("A24000:O24000").Copy
     Sheets("transactions").Range("A24001:O" & lastRow).PasteSpecial xlPasteFormats
     Sheets("transactions").Range("A24001:O" & lastRow).PasteSpecial xlPasteValidation
 

Excel Facts

Bring active cell back into view
Start at A1 and select to A9999 while writing a formula, you can't see A1 anymore. Press Ctrl+Backspace to bring active cell into view.
I think the problem was I had one big Macro running all at once. Only put part of it here.
So I broke it up in sections: Import:remove duplicates: reformat.
I used call macros to run them and so for it works. Time will tell.

If anyone has a way to use remove duplicates without removing formatting please post so one procedure can be removed.
 
Upvote 0
Solution

Forum statistics

Threads
1,223,885
Messages
6,175,184
Members
452,615
Latest member
bogeys2birdies

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