Delete data based on condtion

smartguy

Well-known Member
Joined
Jul 14, 2009
Messages
778
Hello all,

Good day. I have excel file in the below format.

If Condition "ZJ" i need to remove entire row .

For example :

"O2" contain "ZJ" i need to remove from "2" to "12" Row.

"O21" contain "ZJ" i need to remove from "21" to "26" Row.


Please help Excel MVP & Excel expert.




Excel 2013/2016
ABCDEFGHIJKLMNO
1Socument no
210ZJ
3sasa
4sasa
5sasa
6sasa
7sasa
8sasa
9sasa
10sasa
11
12
1320sasa
14sasasasasasasasa
1530
16
1740
18
19
20
2150ZJ
22sasasaasasa
23saa
24sasa
25sasa
26sasa
2760
28
29sasa
30sasa

<colgroup><col style="width: 25pxpx"><col><col><col><col><col><col><col><col><col><col><col><col><col><col><col></colgroup><thead>
</thead><tbody>
</tbody>
Sheet1
 

Excel Facts

Will the fill handle fill 1, 2, 3?
Yes! Type 1 in a cell. Hold down Ctrl while you drag the fill handle.
Try this:-
NB:- This code will alter your sheet data !!!
Code:
[COLOR="Navy"]Sub[/COLOR] MG28Mar15
[COLOR="Navy"]Dim[/COLOR] Rng [COLOR="Navy"]As[/COLOR] Range, Dn [COLOR="Navy"]As[/COLOR] Range, R [COLOR="Navy"]As[/COLOR] Range, nRng [COLOR="Navy"]As[/COLOR] Range
[COLOR="Navy"]Set[/COLOR] Rng = Range("A:A").SpecialCells(xlCellTypeBlanks)
[COLOR="Navy"]For[/COLOR] [COLOR="Navy"]Each[/COLOR] Dn [COLOR="Navy"]In[/COLOR] Rng.Areas
    [COLOR="Navy"]If[/COLOR] Dn(1).Offset(-1, 14) = "ZJ" [COLOR="Navy"]Then[/COLOR]
        [COLOR="Navy"]Set[/COLOR] R = Dn.Offset(-1).Resize(Dn.Count + 1)
        [COLOR="Navy"]If[/COLOR] nRng [COLOR="Navy"]Is[/COLOR] Nothing [COLOR="Navy"]Then[/COLOR] [COLOR="Navy"]Set[/COLOR] nRng = R Else [COLOR="Navy"]Set[/COLOR] nRng = Union(nRng, R)
    [COLOR="Navy"]End[/COLOR] If
[COLOR="Navy"]Next[/COLOR] Dn
[COLOR="Navy"]If[/COLOR] Not nRng [COLOR="Navy"]Is[/COLOR] Nothing [COLOR="Navy"]Then[/COLOR] nRng.EntireRow.Delete
[COLOR="Navy"]End[/COLOR] [COLOR="Navy"]Sub[/COLOR]
Regards Mick
 
Upvote 0
Thank you Mickg

Your my life saver....

hass.gif
 
Upvote 0
Hi Mickg,

If there is any blank column in B or C Column macro is not deleting entire row...

macro missed the blank row.

Please help.
 
Upvote 0

Forum statistics

Threads
1,215,821
Messages
6,127,059
Members
449,356
Latest member
tstapleton67

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