deleting rows based on a condition

Danny54

Active Member
Joined
Jul 3, 2019
Messages
295
Office Version
  1. 365
Platform
  1. Windows
Can someone point me to a vba process that would spin thru column "A" and delete any row where only one (type) is found.
in the following there are two web01, web02 web03 and app03, so they would remain. Only one row is found for app01 and app02 so they would be deleted.


Suggestions would be appreciated.

Thanks



1583254858199.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.
Try this

VBA Code:
Sub DeleteRows()
    Dim Cel As Range, uRng As Range
    Set uRng = Range("A" & Rows.Count)
    For Each Cel In Range("A1", uRng.End(xlUp))
        If WorksheetFunction.CountIf(Range("A:A"), Cel) = 1 Then Set uRng = Union(uRng, Cel)
    Next Cel
    uRng.EntireRow.Delete
End Sub
 
Upvote 0
Sweet.

can you briefly explain what the line does?

If WorksheetFunction.CountIf(Range("A:A"), Cel) = 1 Then Set uRng = Union(uRng, Cel)

I know were using the countif function whereas column A as the range. What's not clear is the rest of the line.


Thanks so much for your help!
 
Upvote 0
Yes,
the code was exactly what i needed.

Thanks so much :)
 
Upvote 0
can you briefly explain what the line does?
I know were using the countif function whereas column A as the range. What's not clear is the rest of the line.

VBA Code:
If WorksheetFunction.CountIf(Range("A:A"), Cel) = 1 Then Set uRng = Union(uRng, Cel)

I am using uRng to collect every cell in column A where the value in that cell appears only once
Using your data , and looping through cells starting at A1

A1 : the value appears twice in column A - DO NOTHING
A2 : same as A1
A3 : same as A1
A4 : same as A1
A5 : same as A1
A6 : same as A1
A7 : the value appears ONCE in column A - include cel A7 in uRng
A8 : same as A7 - include cel A8 in uRng
A9 : same as A1 - DO NOTHING
A10:same as A1

Then all rows included in uRng are deleted
 
Upvote 0

Forum statistics

Threads
1,224,820
Messages
6,181,162
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