Remove duplicates macro removes formulas from the column

IrishMen

New Member
Joined
Sep 17, 2014
Messages
10
Hi

Have another issue:

I have a formula in column D =TRIM(E)
Also I need to remove duplicated values in the sheet based on D column, however when I run remove duplicates macro - all of my formulas are being removed as well.
I have been offered to try the following code:

Sub Remove_duplicates()

Add_Unique (ActiveSheet.range("E2:E2000")<wbr>)


Rows("2:2000").Select
range("BM2").Activate
ActiveSheet.range("$A$2:$CG$<wbr>2000").RemoveDuplicates Columns:=5, Header:=xlNo
range("A2").Select

Remove_Unique (ActiveSheet.range("E2:E2000")<wbr>)

End Sub


Sub Add_Unique(range As range)

Application.ScreenUpdating = False

Dim uniqueValue As Integer


For Each c In range
If c.Value = "" Then
uniqueValue = uniqueValue - 1
c.FormulaR1C1 = uniqueValue
End If
Next c

End Sub


Sub Remove_Unique(range As range)

Dim uniqueValue As Integer


For Each c In range
If c.Value < 0 Then
c.FormulaR1C1 = ""
End If
Next c

Application.ScreenUpdating = True

End Sub

But it doesn't work..

Any suggestions how to fix the issue?

Thank you


 

Excel Facts

What is the shortcut key for Format Selection?
Ctrl+1 (the number one) will open the Format dialog for whatever is selected.
You can't remove duplicates from a column that uses formulas without removing the formula. If you put the formula back with the macro, you will just undo what the remove duplicates macro just did. My suggestion to you is to not use a formula in your column. Instead, tell your macro to insert the formula into the column, then run the remove duplicates macro.
For example:
Range("A1").value = "=5+5"
Range("A1").value = Range("A1").value
'Then run your duplicate macro

So the code abovewill first insert the formula 5+5. Then it will take the result which is 10 and print the result to the cell. This gets rid of the formula. Then run your remove duplicate macro.
 
Upvote 0

Forum statistics

Threads
1,214,924
Messages
6,122,294
Members
449,077
Latest member
Rkmenon

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