macro to Delete Rows where Ref is the Same and the branch in Col C contains statement

howard

Well-known Member
Joined
Jun 26, 2006
Messages
6,561
Office Version
  1. 2021
Platform
  1. Windows
I have references in Col B, Branch in Col C and Values in Col D

where the Reference is the Same in Col B and branch contains PL and statement and the statement Value is Zero , then then rows containing both the references are to be deleted


See link to sample data below , where I have indicated in red those rows to be deleted

It would be appreciated if someone would kindly provide me with code to do this



Have also posted on macro to Delete Rows where Ref is the Same
 

Excel Facts

What is =ROMAN(40) in Excel?
The Roman numeral for 40 is XL. Bill "MrExcel" Jelen's 40th book was called MrExcel XL.
Hi. Try this, please.
VBA Code:
Sub DeleteRows()
 Dim LR As Long
  Application.ScreenUpdating = False
  With ActiveSheet
   .AutoFilterMode = False
   .[E:E] = ""
   LR = .Cells(Rows.Count, 1).End(3).Row
   .Range("E2:E" & LR) = _
   "=IF(COUNTIFS(B$2:B$" & LR & ",""*""&""PL"",C$2:C$" & LR & ",C2)+COUNTIFS(C$2:C$" & LR & ",C2,D$2:D$" & LR & ",0)>1,""TBD"","""")"
   .Range("A1:E" & LR).AutoFilter 5, "TBD"
    If .AutoFilter.Range.Columns(1).SpecialCells(xlCellTypeVisible).Count > 1 Then
     .Range("A2:A" & LR).EntireRow.Delete
    End If
   .AutoFilterMode = False
   .[E:E] = ""
  End With
End Sub
 
Upvote 0
Thanks for the help

Where the Reference is duplicated in Col B and where the value for the second reference for branch containing "Statement" is zero, then those rows must be deleted

I have highlighted the rows to be deleted in yellow so you can get a better understanding of what I am trying to achieve



Your assistance in modifying your code is appreciated
 
Upvote 0
See if I correctly understood what you meant. To work on the second sheet, which has a different lay out from the first one, just replace the formula to the code with this one below.
VBA Code:
    "=IF(COUNTIFS(C$2:C$" & LR & ",""*""&""Statement"",B$2:B$" & LR & ",B2)+COUNTIFS(B$2:B$" & LR & ",B2,D$2:D$" & LR & ",0)>1,""TBD"","""")"
 
Upvote 0

Forum statistics

Threads
1,214,923
Messages
6,122,283
Members
449,075
Latest member
staticfluids

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