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

Is there a shortcut key for strikethrough?
Ctrl+S is used for Save. Ctrl+5 is used for Strikethrough. Why Ctrl+5? When you use hashmarks to count |||| is 4, strike through to mean 5.
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,215,069
Messages
6,122,959
Members
449,096
Latest member
Anshu121

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