Deleting Rows with Duplicate Data in a User defined Column

Philip1957

Board Regular
Joined
Sep 30, 2014
Messages
185
Office Version
  1. 365
Platform
  1. Windows
Greetings,

Some days I amaze myself, other days I have trouble putting my socks on.

This should be an easy macro to create, but I'm just not having any success.

I want a macro for my (or someone else's) Personal.xlsb that will remove rows based on duplicate data in a column specified by the user.

I've got this:

Code:
Option Explicit

Sub Rmv_Dupe_Rows()

Application.ScreenUpdating = False

'On Error Resume Next

Dim clmn As String

clmn = Application.InputBox("Enter the letter designating" & vbCrLf & "the column where the duplicate" & vbCrLf & "data is located.")

ActiveSheet.UsedRange.RemoveDuplicates Columns:=clmn, Header:=xlGuess

Application.ScreenUpdating = True

End Sub

clmn gets saved, I can see it in the Locals window.

I get a Run-time error '13': Type mismatch at the line
Code:
ActiveSheet.UsedRange.RemoveDuplicates Columns:=clmn, Header:=xlGuess

Any assistance would be greatly appreciated.

Thanks in advance for your time,
~ Phil
 

Excel Facts

Links? Where??
If Excel says you have links but you can't find them, go to Formulas, Name Manager. Look for old links to dead workbooks & delete.
The clmn value needs to ba a number not a string.
Are you happy getting the user to enter the column number rather than the column letter?
 
Last edited:
Upvote 0
The function uses column number, not column letter.
You can make some minor modifications to your code to convert it so that it will work with your current structure:
Code:
Sub Rmv_Dupe_Rows()

    Application.ScreenUpdating = False

'   On Error Resume Next

    Dim clmn As String
    Dim col As Long

'   Prompt for column letter
    clmn = Application.InputBox("Enter the letter designating" & vbCrLf & "the column where the duplicate" & vbCrLf & "data is located.")
'   Convert to column number
    col = Cells(1, clmn).Column
    
    ActiveSheet.UsedRange.RemoveDuplicates Columns:=col, Header:=xlGuess
    
    Application.ScreenUpdating = True

End Sub
 
Upvote 0
Thanks for the response!

I don't know that the end users will necessarily understand that they need to count the columns rather than use the letter.

Many of them don't even know how to use VLOOKUP.

I've gotten a solution from another contributor.

Thanks anyway.
 
Upvote 0
Joe4,

I didn't realize the function required a numeric input for the column.

Like I said, sometimes I amaze myself, other times ... not so much.

Thank you for your speedy response!

Your modification to my code works perfectly.

Thanks again,
~ Phil
 
Upvote 0
You are welcome!
Glad we could help.
 
Upvote 0

Forum statistics

Threads
1,223,264
Messages
6,171,085
Members
452,378
Latest member
Hoodzy01

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