Remove values from some cells based on duplicates in one column

HeatherF

New Member
Joined
Mar 3, 2020
Messages
32
Office Version
  1. 2016
Platform
  1. Windows
Hello,
I have a spreadsheet where I would like to remove duplicate values from columns A-E based on duplicates in column C (or B, either will work--not sure if it is easier to use a number or text column). I want to leave the A-E data in the first row that a name appears, but blank it out below, until a row with a new name.

I thought I had a solution using the formulas below, but it's blanking everything:
A1: =IF(C1=C2,"",A1)
B1: =IF(C1=C2,"",B1)
C1: =IF(C1=C2,"",C1)
D1: =IF(C1=C2,"",D1)
E1: =IF(C1=C2,"",E1)

The tables below are TABLEA: What I'm starting with; TABLEB: What I want to achieve; TABLEC: What happens when I apply the formulas.

Thank you for your help!!

Heather

Book1
ABCDEFGHIJ
1AffiliationID#Pref Name w SuffixRating5-yr GivingRelation IdRelation TypeRelation Pref Name w SuffixRelation RatingRelation 5-yr Giving
2PHYSICS10023868Mr. Doug M. Worman '96CW$ 170.007009006ParentMr. Matthias B. Worman '70 P'05 '966$ 28,000.00
3PHYSICS10023868Mr. Doug M. Worman '96CW$ 170.0010043556SiblingMrs. Suzy Lantsman '05CW$ 450.00
4PHYSICS10023868Mr. Doug M. Worman '96CW$ 170.0010022938ParentMrs. Matthias B. Worman P'05 '966$ -
5CREW10024167Ms. Mickey J. Nesmith '966$ 12,500.0010024647ParentMr. & Mrs. John F. Nesmith P'968$ -
6AGENTS10025692Mr. John Forge '979$ 2,750.0010015288SiblingMs. Kristin J. Forge '928$ 400,000.00
7AGENTS10025692Mr. John Forge '979$ 2,750.0010073058InlawMr. Steve Casey 8$ -
8AGENTS10025692Mr. John Forge '979$ 2,750.006529599ParentDr. H. James Forge (dec'd) '65 P'97 '929$ 100,215.00
9AGENTS10025692Mr. John Forge '979$ 2,750.0010029576ParentMrs. Alison Forge H'65 P'97 '929$ -
10FYE10025906Mr. Mike D. Ransick '97CW$ -10008283InlawMr. Michael J. Swiss '89 P'206$ 280,620.00
11FYE10025906Mr. Mike D. Ransick '97CW$ -10076742InlawMs. Kristen E. Swiss P'206$ 7,500.00
12FYE10025906Mr. Mike D. Ransick '97CW$ -10076736NieceMs. Cecilia A. Swiss '20CW$ -
13CREW10028268Mrs. Laura Douglas '97CW$ 850.0010084011StepparentMs. Laura Baker 6$ -
14CREW10028268Mrs. Laura Douglas '97CW$ 850.006221340ParentMr. Carl B. Douglas '62 P'98 '926$ 4,366.41
15CREW10028268Mrs. Laura Douglas '97CW$ 850.0010015662SiblingMr. Blake T. Douglas '92CW$ 100.00
16CREW10028268Mrs. Laura Douglas '97CW$ 850.003421331GrandparentDr. Carl Douglas, Jr. (dec'd) '34 P'62 GP'98 '92U$ -
17PHYSICS10028413Mrs. Jennifer Maitland '98$ 1,286.90
18CREW10030463Ms. Winter Morgan '99CW$ 45,000.0010030843ParentMr. & Mrs. Joseph Wallis P'997$ -
TABLEA


Book1
ABCDEFGHIJ
1AffiliationID#Pref Name w SuffixRating5-yr GivingRelation IdRelation TypeRelation Pref Name w SuffixRelation RatingRelation 5-yr Giving
2PHYSICS10023868Mr. Doug M. Worman '96CW$ 170.007009006ParentMr. Matthias B. Worman '70 P'05 '966$ 28,000.00
310043556SiblingMrs. Suzy Lantsman '05CW$ 450.00
410022938ParentMrs. Matthias B. Worman P'05 '966$ -
5CREW10024167Ms. Mickey J. Nesmith '966$ 12,500.0010024647ParentMr. & Mrs. John F. Nesmith P'968$ -
6AGENTS10025692Mr. John Forge '979$ 2,750.0010015288SiblingMs. Kristin J. Forge '928$ 400,000.00
710073058InlawMr. Steve Casey 8$ -
86529599ParentDr. H. James Forge (dec'd) '65 P'97 '929$ 100,215.00
910029576ParentMrs. Alison Forge H'65 P'97 '929$ -
10FYE10025906Mr. Mike D. Ransick '97CW$ -10008283InlawMr. Michael J. Swiss '89 P'206$ 280,620.00
1110076742InlawMs. Kristen E. Swiss P'206$ 7,500.00
1210076736NieceMs. Cecilia A. Swiss '20CW$ -
13CREW10028268Mrs. Laura Douglas '97CW$ 850.0010084011StepparentMs. Laura Baker 6$ -
146221340ParentMr. Carl B. Douglas '62 P'98 '926$ 4,366.41
1510015662SiblingMr. Blake T. Douglas '92CW$ 100.00
163421331GrandparentDr. Carl Douglas, Jr. (dec'd) '34 P'62 GP'98 '92U$ -
17PHYSICS10028413Mrs. Jennifer Maitland '98$ 1,286.90
18CREW10030463Ms. Winter Morgan '99CW$ 45,000.0010030843ParentMr. & Mrs. Joseph Wallis P'997$ -
TABLEB


Book1
ABCDEFGHIJ
1AffiliationID#Pref Name w SuffixRating5-yr GivingRelation IdRelation TypeRelation Pref Name w SuffixRelation RatingRelation 5-yr Giving
2 000$ -7009006ParentMr. Matthias B. Worman '70 P'05 '966$ 28,000.00
3 000$ -10043556SiblingMrs. Suzy Lantsman '05CW$ 450.00
4 000$ -10022938ParentMrs. Matthias B. Worman P'05 '966$ -
5 000$ -10024647ParentMr. & Mrs. John F. Nesmith P'968$ -
6 000$ -10015288SiblingMs. Kristin J. Forge '928$ 400,000.00
7 000$ -10073058InlawMr. Steve Casey 8$ -
8 000$ -6529599ParentDr. H. James Forge (dec'd) '65 P'97 '929$ 100,215.00
9 000$ -10029576ParentMrs. Alison Forge H'65 P'97 '929$ -
10 000$ -10008283InlawMr. Michael J. Swiss '89 P'206$ 280,620.00
11 000$ -10076742InlawMs. Kristen E. Swiss P'206$ 7,500.00
12 000$ -10076736NieceMs. Cecilia A. Swiss '20CW$ -
13 000$ -10084011StepparentMs. Laura Baker 6$ -
14 000$ -6221340ParentMr. Carl B. Douglas '62 P'98 '926$ 4,366.41
15 000$ -10015662SiblingMr. Blake T. Douglas '92CW$ 100.00
16 000$ -3421331GrandparentDr. Carl Douglas, Jr. (dec'd) '34 P'62 GP'98 '92U$ -
17 000$ -
18 000$ -10030843ParentMr. & Mrs. Joseph Wallis P'997$ -
TABLEC
Cell Formulas
RangeFormula
A2:A18A2=IF(C2=C3,"",A2)
B2:B18B2=IF(C2=C3,"",B2)
C2:C18C2=IF(C2=C3,"",C2)
D2:D18D2=IF(C2=C3,"",D2)
E2:E18E2=IF(C2=C3,"",E2)
 

Excel Facts

Add Bullets to Range
Select range. Press Ctrl+1. On Number tab, choose Custom. Type Alt+7 then space then @ sign (using 7 on numeric keypad)
Reduce your C values by 1 in your formulas.

ie. =IF(C1=C2,"",A2) etc.
 
Upvote 0
Reduce your C values by 1 in your formulas.

ie. =IF(C1=C2,"",A2) etc.
Thank you, of course, that makes sense. Can I ask something really dumb? I can't seem to add formulas to cells without deleting the cell values. When I click fx it brings up the formula builder dialog but I just want to paste a formula. I swear it used to just insert an = . Did I mess up a setting?
 
Upvote 0
If you just want to paste a formula, paste it into the long box to the right of the 'fx'

You can't use the formulas in the manner that you are trying. As you noticed, when you put a formula in a cell it will replace the current value of the cell.

I believe you need to use vba macro code to accomplish your goal.
 
Upvote 0
I have tried to figure out a VBA macro. That would be ideal. I entered the one below, but it removes the entire row with duplicate data, and I only want to remove the values.

Sub removeDuplicate()
'removeDuplicate Macro
Columns("C:C").Select
ActiveSheet.Range("$A$1:$J$18").RemoveDuplicates Columns:=Array(1), _
Header:=xlNo
Range("A1").Select
End Sub
 
Upvote 0
How about this:

VBA Code:
Sub RemoveSomeCells()
'
    Dim ArrayRow        As Long
    Dim LastRowInSheet  As Long
    Dim SavedArray      As Variant
'
    LastRowInSheet = Cells.Find("*", , xlFormulas, , xlByRows, xlPrevious).Row              ' Returns a Row Number
'
    SavedArray = Range("A1:E" & LastRowInSheet)                                             ' Save values into 2 dimensional 1 based Array ... 5 wide
'
    For ArrayRow = UBound(SavedArray) To 2 Step -1                                          ' Work backwards through rows because we will be deleting values
        If SavedArray(ArrayRow, 3) = SavedArray(ArrayRow - 1, 3) Then                       '   If This row value = previous row value then ...
            SavedArray(ArrayRow, 1) = vbNullString                                          '       Delete the value from the A column
            SavedArray(ArrayRow, 2) = vbNullString                                          '       Delete the value from the B column
            SavedArray(ArrayRow, 3) = vbNullString                                          '       Delete the value from the C column
            SavedArray(ArrayRow, 4) = vbNullString                                          '       Delete the value from the D column
            SavedArray(ArrayRow, 5) = vbNullString                                          '       Delete the value from the E column
        End If
    Next                                                                                    ' Loop back to do next check
'
    Range("A1:E" & LastRowInSheet) = SavedArray                                             ' Print the saved array back to the sheet

End Sub

I left the code a bit long to make it easier to understand.
 
Upvote 0
Solution
Hi again, I am trying to adjust this to my real spreadsheet, and the columns where I'd like to delete dupe values is A-X. Since I edited the code, it's just deleting columns A-X after row 2. What am I doing wrong? Thanks so much for your help!

VBA Code:
Sub RemoveSomeCells()
'
    Dim ArrayRow        As Long
    Dim LastRowInSheet  As Long
    Dim SavedArray      As Variant
'
    LastRowInSheet = Cells.Find("*", , xlFormulas, , xlByRows, xlPrevious).Row              ' Returns a Row Number
'
    SavedArray = Range("A1:X" & LastRowInSheet)                                             ' Save values into 2 dimensional 1 based Array ... 24 wide
'
    For ArrayRow = UBound(SavedArray) To 2 Step -1                                          ' Work backwards through rows because we will be deleting values
        If SavedArray(ArrayRow, 3) = SavedArray(ArrayRow - 1, 3) Then                       '   If This row value = previous row value then ...
            SavedArray(ArrayRow, 1) = vbNullString                                          '       Delete the value from the A column
            SavedArray(ArrayRow, 2) = vbNullString                                          '       Delete the value from the B column
            SavedArray(ArrayRow, 3) = vbNullString                                          '       Delete the value from the C column
            SavedArray(ArrayRow, 4) = vbNullString                                          '       Delete the value from the D column
            SavedArray(ArrayRow, 5) = vbNullString                                          '       Delete the value from the E column
            SavedArray(ArrayRow, 6) = vbNullString                                          '       Delete the value from the F column
            SavedArray(ArrayRow, 7) = vbNullString                                          '       Delete the value from the G column
            SavedArray(ArrayRow, 8) = vbNullString                                          '       Delete the value from the H column
            SavedArray(ArrayRow, 9) = vbNullString                                          '       Delete the value from the I column
            SavedArray(ArrayRow, 10) = vbNullString                                          '       Delete the value from the J column
            SavedArray(ArrayRow, 11) = vbNullString                                          '       Delete the value from the K column
            SavedArray(ArrayRow, 12) = vbNullString                                          '       Delete the value from the L column
            SavedArray(ArrayRow, 13) = vbNullString                                          '       Delete the value from the M column
            SavedArray(ArrayRow, 14) = vbNullString                                          '       Delete the value from the N column
            SavedArray(ArrayRow, 15) = vbNullString                                          '       Delete the value from the O column
            SavedArray(ArrayRow, 16) = vbNullString                                          '       Delete the value from the P column
            SavedArray(ArrayRow, 17) = vbNullString                                          '       Delete the value from the Q column
            SavedArray(ArrayRow, 18) = vbNullString                                          '       Delete the value from the R column
            SavedArray(ArrayRow, 19) = vbNullString                                          '       Delete the value from the S column
            SavedArray(ArrayRow, 20) = vbNullString                                          '       Delete the value from the T column
            SavedArray(ArrayRow, 21) = vbNullString                                          '       Delete the value from the U column
            SavedArray(ArrayRow, 22) = vbNullString                                          '       Delete the value from the V column
            SavedArray(ArrayRow, 23) = vbNullString                                          '       Delete the value from the W column
            SavedArray(ArrayRow, 24) = vbNullString                                          '       Delete the value from the X column
        End If
    Next                                                                                    ' Loop back to do next check
'
    Range("A1:X" & LastRowInSheet) = SavedArray                                             ' Print the saved array back to the sheet

End Sub
 
Upvote 0
Your question confuses me. Row 2 is the first row of data, at least it was in your original post.

If it is the first row of data, it can't be a duplicate to anything above it, therefore it won't be deleted.

Perhaps you can post some more of what you are expecting vs what you are getting.
 
Upvote 0
Sorry, that was unclear. The code you gave me worked perfectly—deleting duplicate values in columns A-E while preserving the first instance of those values. So when A-E repeats in rows 2,3,4 but new values are in row 5, A-E are deleted in rows 3,4 but preserved in rows 2 & 5.

When I tried to expand the code to include columns A-X, now it is preserving row2, but deleting the values in A-X from row 3 onwards, whether it’s a duplicate of the row above it or not.
 
Upvote 0
I don't see an issue with the code you posted. Have you tried a reboot of the computer and then test it?

If you could post the data like you did in post 1 so we can test it to see if we can duplicate the problem, that would be my suggestion.
 
Upvote 0

Forum statistics

Threads
1,224,823
Messages
6,181,176
Members
453,021
Latest member
Justyna P

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