How to keep only the top row of a value and delete the rest of the rows

Pupishi

New Member
Joined
Oct 27, 2020
Messages
9
Office Version
  1. 2016
Platform
  1. Windows
Hello,

I am new to VBA and would like to get assistance from the experts if possible.

I have a number of duplicated booking numbers with different data captured in subsequent columns.
In order to identify the duplicated bookings, I have numbered them in column FL (FYI, the number of duplicated bookings will increase each day).
Now I am manually keeping the values in the first record of a number in column FL and deleting the rest manually in columns BP to BX (not rows but the values).
Would there be a VBA that would automate this process?

Any help I could get is greatly appreciated.
Thank you.
 

Attachments

  • Example Screenshot.png
    Example Screenshot.png
    33.2 KB · Views: 14

Excel Facts

How to find 2nd largest value in a column?
MAX finds the largest value. =LARGE(A:A,2) will find the second largest. =SMALL(A:A,3) will find the third smallest
How about
VBA Code:
Sub Pupishi()
   Dim Cl As Range
   
   With CreateObject("scripting.dictionary")
      For Each Cl In Range("A2", Range("A" & Rows.Count).End(xlUp))
         If Not .Exists(Cl.Value) Then
            .Add Cl.Value, Nothing
         Else
            Range("BP" & Cl.Row).Resize(, 9).ClearContents
         End If
      Next Cl
   End With
End Sub
 
Upvote 0
Solution
How about
VBA Code:
Sub Pupishi()
   Dim Cl As Range
  
   With CreateObject("scripting.dictionary")
      For Each Cl In Range("A2", Range("A" & Rows.Count).End(xlUp))
         If Not .Exists(Cl.Value) Then
            .Add Cl.Value, Nothing
         Else
            Range("BP" & Cl.Row).Resize(, 9).ClearContents
         End If
      Next Cl
   End With
End Sub
Amazing!! It worked perfectly. Thank you so much!
 
Upvote 0
You're welcome & thanks for the feedback.
 
Upvote 0

Forum statistics

Threads
1,214,983
Messages
6,122,583
Members
449,089
Latest member
Motoracer88

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