Excel VBA Problem

Blobajob88

Board Regular
Joined
Mar 27, 2020
Messages
55
Office Version
  1. 365
  2. 2019
Platform
  1. Windows
Hi,

Can someone please help. For some reason, I cannot get the below code to work. I want it to delete the rows if there is a duplicate with the cells in column 3. It worked before but all of sudden it doesn't. When I change the number to column 4, 2, 8 or anything other than 3, it works fine. Can someone help urgently? The column titled 'description' is column 3

1585293178654.png
 

Excel Facts

Move date out one month or year
Use =EDATE(A2,1) for one month later. Use EDATE(A2,12) for one year later.
It would be easier for anyone trying to help you if you posted the whole of your code rather than a picture of part of it
Click on <vba/> and paste your code between the code tags and do NOT try to format anything
 
Upvote 0
I agree with Yongle about posting actual code (or a download URL that points to the Excel file or exported ".bas" file).

And while I cannot determine the intended code because some of it is commented out, things might work as intended if you add Exit For after the Delete statement. Something like:

VBA Code:
If Cells(i, 3) = Cells(i-j, 3) Then
    Rows(i).Delete shift:=xlUp
    Exit For
End If


FYI, note that you do not need to do Rows(i).Select.

Note: Exit For exits only the innermost for-loop. And that seems to be all you need.
 
Upvote 0
alternatively you could remove the duplicates using the removeduplicates function
change the range to your dynamic range and header to yes if you have headers within the range

VBA Code:
ActiveSheet.Range("$B$2:$D$6").RemoveDuplicates Columns:=3, Header:=xlNo
 
Upvote 0

Forum statistics

Threads
1,215,429
Messages
6,124,839
Members
449,193
Latest member
MikeVol

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