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
-
WSHansV
AskWoody Lounger -
WSJezza
AskWoody Lounger
-
-
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
-
Notice on termination of services of LG Mobile Phone Software Updates
by
Alex5723
57 minutes ago -
Update your Apple Devices Wormable Zero-Click Remote Code Execution in AirPlay..
by
Alex5723
7 hours, 55 minutes ago -
Amazon denies it had plans to be clear about consumer tariff costs
by
Alex5723
52 minutes ago -
Return of the brain dead FF sidebar
by
EricB
4 hours, 56 minutes ago -
windows settings managed by your organization
by
WSDavidO61
9 hours, 1 minute ago -
Securing Laptop for Trustee Administrattor
by
PeachesP
9 hours, 13 minutes ago -
The local account tax
by
Susan Bradley
36 minutes ago -
Recall is back with KB5055627(OS Build 26100.3915) Preview
by
Alex5723
20 hours, 55 minutes ago -
Digital TV Antenna Recommendation
by
Win7and10
13 hours, 27 minutes ago -
Server 2019 Domain Controllers broken by updates
by
MP Support
1 day, 8 hours ago -
Google won’t remove 3rd party cookies in Chrome as promised
by
Alex5723
1 day, 10 hours ago -
Microsoft Manager Says macOS Is Better Than Windows 11
by
Alex5723
1 day, 13 hours ago -
Outlook (NEW) Getting really Pushy
by
RetiredGeek
16 hours, 5 minutes ago -
Steps to take before updating to 24H2
by
Susan Bradley
6 hours, 54 minutes ago -
Which Web browser is the most secure for 2025?
by
B. Livingston
20 hours, 31 minutes ago -
Replacing Skype
by
Peter Deegan
9 hours, 4 minutes ago -
FileOptimizer — Over 90 tools working together to squish your files
by
Deanna McElveen
1 day, 7 hours ago -
Excel Macro — ask for filename to be saved
by
nhsj
5 hours, 1 minute ago -
Trying to backup Win 10 computer to iCloud
by
SheltieMom
8 hours, 50 minutes ago -
Windows 11 Insider Preview build 26200.5570 released to DEV
by
joep517
3 days, 13 hours ago -
Windows 11 Insider Preview build 26120.3941 (24H2) released to BETA
by
joep517
3 days, 15 hours ago -
Windows 11 Insider Preview Build 22635.5305 (23H2) released to BETA
by
joep517
3 days, 15 hours ago -
No April cumulative update for Win 11 23H2?
by
Peobody
2 days, 3 hours ago -
AugLoop.All (TEST Augmentation Loop MSIT)
by
LarryK
3 days, 15 hours ago -
Boot Sequence for Dell Optiplex 7070 Tower
by
Serge Carniol
4 days, 7 hours ago -
OTT Upgrade Windows 11 to 24H2 on Unsupported Hardware
by
bbearren
58 minutes ago -
Inetpub can be tricked
by
Susan Bradley
2 days, 18 hours ago -
How merge Outlook 2016 .pst file w/into newly created Outlook 2024 install .pst?
by
Tex265
3 days, 4 hours ago -
FBI 2024 Internet Crime Report
by
Alex5723
4 days, 14 hours ago -
Perplexity CEO says its browser will track everything users do online
by
Alex5723
1 day, 23 hours 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.