Delete and shift cells up

Chewyhairball

Active Member
Joined
Nov 30, 2017
Messages
312
Office Version
  1. 365
Platform
  1. Windows
Hi folks

Looking for VBA to find duplicate values in ID column and delete them by shifting cells up. (not deleting whole row). Thanks

Example below is what I want.

Actual table range will be B2:E22
1658162041729.png
to this
1658162120714.png
 
Also, when quoting code from a previous post, please ensure that you select the code heading at the top as well as the code itself
1658454533857.png


That way the code will appear correctly laid out and readable as below (when expanded if required) instead of the virtually impossible to read code as in your post #7

VBA Code:
Code:
Sub ReoveDuplicateIDRows_2()
  Dim rDupes As Range
 
  With Range("B2:E22")
    Range("G3").Formula = "=COUNTIF(" & .Columns(1).Address & "," & .Cells(2, 1).Address(0, 0) & ")>1"
    .AdvancedFilter Action:=xlFilterInPlace, CriteriaRange:=Range("G2:G3"), Unique:=False
    If .Columns(1).SpecialCells(xlVisible).Count > 1 Then
      Set rDupes = .Offset(1).Resize(.Rows.Count - 1).SpecialCells(xlVisible)
      .Parent.ShowAllData
      rDupes.Delete Shift:=xlUp
    Else
      .Parent.ShowAllData
    End If
    Range("G3").ClearContents
  End With
End Sub
 
Upvote 0

Excel Facts

Control Word Wrap
Press Alt+Enter to move to a new row in a cell. Lets you control where the words wrap.

Forum statistics

Threads
1,214,940
Messages
6,122,356
Members
449,080
Latest member
Armadillos

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