Locate matched criterea & delete Rows!

Zshanar69

New Member
Joined
Apr 28, 2020
Messages
17
Office Version
  1. 2010
Platform
  1. Windows
  2. Mobile
  3. Web
Hi,
I have master sheet called "ENTITY"
In column "A" if there's a text "NEXT" but in the same Row column "B" is empty.
now there may be 3 or 300 or 3000 Rows with same criteria,
I want last entry to be found with same criteria & right below that row column "D" ,"G" & "K" must be cleared without changing other cells in single Row,
& below that
every Row to last filled row of column "A" would be deleted!
if anyone could please suggest any VBA macro!

Thanks.
 

Some videos you may like

Excel Facts

What does custom number format of ;;; mean?
Three semi-colons will hide the value in the cell. Although most people use white font instead.

Fluff

MrExcel MVP, Moderator
Joined
Jun 12, 2014
Messages
55,526
Office Version
  1. 365
Platform
  1. Windows
Do you want to find the last row where col A is NEXT or the last row where col A is NEXT and col B is empty?
 

Fluff

MrExcel MVP, Moderator
Joined
Jun 12, 2014
Messages
55,526
Office Version
  1. 365
Platform
  1. Windows
Ok, how about
VBA Code:
Sub Zshanar()
   Dim Rng  As Range
   
   With ActiveSheet
      .Range("A1:B1").AutoFilter 1, "next"
      .Range("A1:B1").AutoFilter 2, ""
      Set Rng = Range("A" & Rows.Count).End(xlUp)
      .AutoFilterMode = False
   End With
   Intersect(Rng.Offset(1).EntireRow, Range("D:D,G:G,K:K")).ClearContents
   Range(Rng.Offset(2), Range("A" & Rows.Count).End(xlUp)).EntireRow.Delete
End Sub
 

Zshanar69

New Member
Joined
Apr 28, 2020
Messages
17
Office Version
  1. 2010
Platform
  1. Windows
  2. Mobile
  3. Web

ADVERTISEMENT

It's just deleting the last Row!
TASKMACRO.jpg
TASK.jpg
 

Fluff

MrExcel MVP, Moderator
Joined
Jun 12, 2014
Messages
55,526
Office Version
  1. 365
Platform
  1. Windows

ADVERTISEMENT

You have blank rows within the data that is causing the problem.
I've got to pop out for a few minutes, but will sort it out when I get back.
 

Fluff

MrExcel MVP, Moderator
Joined
Jun 12, 2014
Messages
55,526
Office Version
  1. 365
Platform
  1. Windows
Ok, how about
VBA Code:
Sub Zshanar()
   Dim Rng  As Range
   Dim UsdRws As Long
   
   With ActiveSheet
      UsdRws = .Range("A" & Rows.Count).End(xlUp).Row
      .Range("A1:B" & UsdRws).AutoFilter 1, "next"
      .Range("A1:B" & UsdRws).AutoFilter 2, ""
      Set Rng = Range("A" & Rows.Count).End(xlUp)
      .AutoFilterMode = False
   End With
   Intersect(Rng.Offset(1).EntireRow, Range("D:D,G:G,K:K")).ClearContents
   Range(Rng.Offset(2), Range("A" & UsdRws)).EntireRow.Delete
End Sub
 
Solution

Zshanar69

New Member
Joined
Apr 28, 2020
Messages
17
Office Version
  1. 2010
Platform
  1. Windows
  2. Mobile
  3. Web
Ok, how about
VBA Code:
Sub Zshanar()
   Dim Rng  As Range
   Dim UsdRws As Long
  
   With ActiveSheet
      UsdRws = .Range("A" & Rows.Count).End(xlUp).Row
      .Range("A1:B" & UsdRws).AutoFilter 1, "next"
      .Range("A1:B" & UsdRws).AutoFilter 2, ""
      Set Rng = Range("A" & Rows.Count).End(xlUp)
      .AutoFilterMode = False
   End With
   Intersect(Rng.Offset(1).EntireRow, Range("D:D,G:G,K:K")).ClearContents
   Range(Rng.Offset(2), Range("A" & UsdRws)).EntireRow.Delete
End Sub
It shows : Run-time error '1004':
Application-defined or object-defined error!
 

Watch MrExcel Video

Forum statistics

Threads
1,127,516
Messages
5,625,264
Members
416,086
Latest member
CaptainGD

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
Top