G’day loungers!
I am trying to figure out how to code the following situation in VBA and am hitting a wall. If the value in column U is equal to 9900 or 9915 and the value in column Y is equal to “CB” or “MB” then I want to delete that row. Any suggestions?
![]() |
Patch reliability is unclear, but widespread attacks make patching prudent. Go ahead and patch, but watch out for potential problems. |
SIGN IN | Not a member? | REGISTER | PLUS MEMBERSHIP |
-
Macro help (2007)
Home » Forums » AskWoody support » Productivity software by function » MS Excel and spreadsheet help » Macro help (2007)
- This topic has 10 replies, 4 voices, and was last updated 16 years, 8 months ago.
AuthorTopicWSgvanhook
AskWoody LoungerAugust 13, 2008 at 5:19 am #453148Viewing 0 reply threadsAuthorReplies-
WSJezza
AskWoody LoungerAugust 13, 2008 at 6:23 am #1121186Hi Greg
Try this piece of code:
Sub RemoveRows() Dim r As Long Dim n As Long r = Range("A" & Rows.Count).End(xlUp).Row For n = r To 1 Step -1 If Cells(r, 21) = 9900 Or Cells(r, 21) = 9915 _ And Cells(r, 25) = "CB" Or Cells(r, 25) = "MB" Then Cells(r, 1).EntireRow.Delete Else End If Next n End Sub
-
WSgvanhook
AskWoody Lounger -
WSHansV
AskWoody LoungerAugust 13, 2008 at 7:00 am #1121193Just a tiny confusion between r and n. Try
Sub RemoveRows()
Dim r As Long
Dim n As Long
r = Range(“A” & Rows.Count).End(xlUp).Row
For n = r To 1 Step -1
If (Cells(n, 21) = 9900 Or Cells(n, 21) = 9915) _
And (Cells(n, 25) = “CB” Or Cells(n, 25) = “MB”) Then
Cells(n, 1).EntireRow.Delete
End If
Next n
End Sub -
WSgvanhook
AskWoody Lounger
-
-
-
WSJezza
AskWoody LoungerAugust 13, 2008 at 7:09 am #1121198Whoops
Sorry, that teach me to send untested code, try:
Sub RemoveRows() Dim r As Long Dim m As Long Dim n As Long r = Range("A" & Rows.Count).End(xlUp).Row For n = r To 1 Step -1 If Cells(n, 21) = 9900 Or Cells(n, 21) = 9915 _ And Cells(n, 25) = "CB" Or Cells(n, 25) = "MB" Then Cells(n, 1).EntireRow.Delete Else End If Next n End Sub
-
WSgvanhook
AskWoody Lounger -
WSVegasNath
AskWoody LoungerAugust 13, 2008 at 7:46 am #1121211Yes, as per Hans post post 727,185
-
WSJezza
AskWoody LoungerAugust 13, 2008 at 7:57 am #1121215Correct
I was rushing my coding so bypassed that issue but it makes good logic to break it down in this way as the parenthesis set precedence similar to the old conundrum of:
What do the following equal
1) 2*3+1
2) 2*(3+1)
3) (2*3)+1Same as
If ( A=1 or A=2) and (B=3 or B=4)
The code will initially check the values in the the lefthand bracket and then check the values in the righthand set. By breaking this down it allows the code to identify the correct precedence for checking values.
So yes you are correct
If (Cells(n,21) = 9900 or Cells(n,21) = 9915) _
And (Cells(n,25) = “CB” or Cells(n,25) = “MB”) Then
Cells(n,1).EntreRow.Delete
-
-
Viewing 0 reply threads -

Plus Membership
Donations from Plus members keep this site going. You can identify the people who support AskWoody by the Plus badge on their avatars.
AskWoody Plus members not only get access to all of the contents of this site -- including Susan Bradley's frequently updated Patch Watch listing -- they also receive weekly AskWoody Plus Newsletters (formerly Windows Secrets Newsletter) and AskWoody Plus Alerts, emails when there are important breaking developments.
Get Plus!
Welcome to our unique respite from the madness.
It's easy to post questions about Windows 11, Windows 10, Win8.1, Win7, Surface, Office, or browse through our Forums. Post anonymously or register for greater privileges. Keep it civil, please: Decorous Lounge rules strictly enforced. Questions? Contact Customer Support.
Search Newsletters
Search Forums
View the Forum
Search for Topics
Recent Topics
-
Win 7 MS Essentials suddenly not showing number of items scanned.
by
Oldtimer
1 hour, 22 minutes ago -
France : A law requiring messaging apps to implement a backdoor ..
by
Alex5723
9 hours, 53 minutes ago -
Dev runs Windows 11 ARM on an iPad Air M2
by
Alex5723
10 hours, 42 minutes ago -
MS-DEFCON 3: Cleanup time
by
Susan Bradley
41 minutes ago -
KB5056686 (.NET v8.0.15) Delivered Twice in April 2025
by
lmacri
6 hours, 7 minutes ago -
How to enable Extended Security Maintenance on Ubuntu 20.04 LTS before it dies
by
Alex5723
21 hours, 55 minutes ago -
Windows 11 Insider Preview build 26200.5562 released to DEV
by
joep517
1 day, 1 hour ago -
Windows 11 Insider Preview build 26120.3872 (24H2) released to BETA
by
joep517
1 day, 1 hour ago -
Unable to eject external hard drives
by
Robertos42
5 hours, 22 minutes ago -
Saying goodbye to not-so-great technology
by
Susan Bradley
1 hour, 41 minutes ago -
Tech I don’t miss, and some I do
by
Will Fastie
6 hours, 59 minutes ago -
Synology limits hard drives
by
Susan Bradley
2 days, 6 hours ago -
Links from Microsoft 365 and from WhatsApp not working
by
rog7
1 day, 8 hours ago -
WhatsApp Security Advisories CVE-2025-30401
by
Alex5723
2 days, 12 hours ago -
Upgrade Sequence
by
doneager
2 days, 5 hours ago -
Chrome extensions with 6 million installs have hidden tracking code
by
Nibbled To Death By Ducks
11 hours, 7 minutes ago -
Uninstall “New Outlook” before installing 2024 Home & Business?
by
Tex265
1 day, 4 hours ago -
The incredible shrinking desktop icons
by
Thumper
3 days, 9 hours ago -
Windows 11 Insider Preview Build 22635.520 (23H2) released to BETA
by
joep517
3 days, 10 hours ago -
Connecting hard drive on USB 3.2 freezes File Explorer & Disk Management
by
WSJMGatehouse
9 hours, 52 minutes ago -
Shellbag Analyser & Cleaner Update
by
Microfix
3 hours, 22 minutes ago -
CISA warns of increased breach risks following Oracle Cloud leak
by
Nibbled To Death By Ducks
3 days, 20 hours ago -
Outlook 2024 two sent from email addresses
by
Kathy Stevens
3 days ago -
Speeding up 11’s search
by
Susan Bradley
1 day, 8 hours ago -
HP Pavilion Will Not Wake Up After Being Idle for Longer Period
by
WSwalterwood44
1 day, 20 hours ago -
Make a Windows 11 Local Account Passwordless
by
Drcard:))
4 days, 10 hours ago -
Ubuntu 25.04 (Plucky Puffin)
by
Alex5723
4 days, 17 hours ago -
24H2 fixed??
by
CWBillow
3 days, 10 hours ago -
Uninstalr Updates
by
jv16
4 days, 22 hours ago -
Apple zero days for April
by
Susan Bradley
19 hours, 25 minutes ago
Recent blog posts
Key Links
Want to Advertise in the free newsletter? How about a gift subscription in honor of a birthday? Send an email to sb@askwoody.com to ask how.
Mastodon profile for DefConPatch
Mastodon profile for AskWoody
Home • About • FAQ • Posts & Privacy • Forums • My Account
Register • Free Newsletter • Plus Membership • Gift Certificates • MS-DEFCON Alerts
Copyright ©2004-2025 by AskWoody Tech LLC. All Rights Reserved.