delete rows based on a specific value in column A only if column B does not equal a different specific value

pzabransky

New Member
Joined
Jul 21, 2008
Messages
1
Can someone please help me with some code.

I need to build a macro, which will delete all rows with a specific value in column A, only if column B does not equal a different specific value. I can't seem to find any relevant posts. thank you very much.

-p
 

Some videos you may like

Excel Facts

Lock one reference in a formula
Need 1 part of a formula to always point to the same range? use $ signs: $V$2:$Z$99 will always point to V2:Z99, even after copying
Joined
Jul 30, 2006
Messages
3,656
pzabransky,

Welcome to the board.

Please post a screenshot of your sheet(s), what you have and what you expect to achieve, with Colo's HTML Maker.
http://www.puremis.net/excel/downloads.shtml

Instructions for using "Colo's HTML Maker":
http://www.mrexcel.com/forum/showthread.php?t=89356


Or, with Excel Jeanie HTML 4.
http://www.excel-jeanie-html.de/index.php?f=1

Instructions for using "Excel Jeanie HTML 4":
http://www.excel-jeanie-html.de/html/hlp_schnell_en.php


I need to build a macro, which will delete all rows with a specific value in column A, only if column B does not equal a different specific value. I can't seem to find any relevant posts. thank you very much.

Please explain in more detail:
What values in column A?
What values in column B?


Have a great day,
Stan
 
Last edited:

MrKowz

Well-known Member
Joined
Jun 30, 2008
Messages
6,653
Office Version
  1. 365
  2. 2016
Platform
  1. Windows
Try the following out, you will have to add in your "specific" values to this.

val1 = the value you want to match in column A

val2 = the value you DONT WANT column B to have

Note: I have not tested this, so be sure to backup your file!

Code:
sub RowDelete()
Dim val1 as variant
Dim val2 as variant
Dim LR as variant
Dim rowx as integer
 
LR = Range("A" & rows.count).End(xlUp).Row
For rowx = LR to 1 Step -1
     If Cells(rowx,1).Value = val1 AND Cells(rowx,2).Value <> val2 Then Rows(rowx).Delete
Next rowx
 

Watch MrExcel Video

Forum statistics

Threads
1,122,521
Messages
5,596,653
Members
414,083
Latest member
Mrsash

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