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
 

Excel Facts

What is the shortcut key for Format Selection?
Ctrl+1 (the number one) will open the Format dialog for whatever is selected.
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:
Upvote 0
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
 
Upvote 0

Forum statistics

Threads
1,214,653
Messages
6,120,750
Members
448,989
Latest member
mariah3

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