Home > Software design >  VBA: Keep first and last rows of duplicate column values of an Excel sheet
VBA: Keep first and last rows of duplicate column values of an Excel sheet

Time:06-16

I have an Excel worksheet with 20K rows like this:

header1 header2
1 P
2 P
3 P
4 Q
5 R
6 R
7 R
8 R
9 S
10 S

I want a VBA code to delete the rows containing duplicates, but keep the first and last row of the duplicates. The result should be like this:

header1 header2
1 P
3 P
4 Q
5 R
8 R
9 S
10 S

I have modified the following code found enter image description here

  • Related