How would I write a macro so that when it is checking the cells data, it will be able to read that the cell has no data and will delete the entire row?
![]() |
There are isolated problems with current patches, but they are well-known and documented on this site. |
SIGN IN | Not a member? | REGISTER | PLUS MEMBERSHIP |
-
Reading Blank Data (English)
Home » Forums » AskWoody support » Productivity software by function » MS Excel and spreadsheet help » Reading Blank Data (English)
- This topic has 20 replies, 5 voices, and was last updated 23 years, 7 months ago.
Viewing 0 reply threadsAuthorReplies-
WSWassim
AskWoody LoungerOctober 24, 2001 at 4:31 pm #548404Ximon
Would that help? This would look for cells in Column A all the way down to the last row of your worksheet and if that cell is empty then it deletes the row.
Sub DeleteBlankRows()
Dim lCounter As LongWith ActiveSheet
For lCounter = 2 To .Rows.Count
If Len(CStr(Range(“A” & lCounter).Value)) = 0 Then
.Rows(lCounter).Select
‘/Cell is blanck so delete row.
.Rows(lCounter).Delete Shift:=xlUp
End If
Next lCounter
End With
End SubWassim
-
WSXimon
AskWoody Lounger -
WSXimon
AskWoody LoungerOctober 24, 2001 at 5:01 pm #548412Hi Wassim,
I tried the macro you wrote for me and it works very good, but there is one thing. When I delete the row I notice that the data from the previous row has moved up a row and so I don’t think I should be deleting entire rows. How would I only delete the data that is in the cells of colume B and C of the selected rowusing your example?
-
H. Legare Coleman
AskWoody PlusOctober 24, 2001 at 5:20 pm #548417I am not clear on what you want to do.
It sounds like you want to delete the data from the cell but if there is no data in the cell, there is nothing there to delete.
If a cell in Column B is empty, do you want to delete the cell and move the rest of the cells in column B up without affecting data that might be in other columns? If the cell in B is empty, do you want to delete the cell in column C even if it contains data, or do you want to only delete cells in column C if they are empty. What do you want to do if one of the cells is empty but the other is not?
-
WSXimon
AskWoody LoungerOctober 24, 2001 at 5:33 pm #548420 -
WSAndrew Cronnolly
AskWoody Lounger -
H. Legare Coleman
AskWoody PlusOctober 24, 2001 at 5:45 pm #548424Ok, I think I am beginning to understand what you want to do. However, one more question before we proceed. Are you really just trying to keep a zero or error from displaying in columns A and B if C is empty, or do you really need to delete the formulas? You can keep the zero or error from displaying by using a simple formula, and then you don’t have to reenter the formula if you later enter something in C. If the formula in A is =1/C1, which will produce an error is C is empty, then you can change the formula to:
=IF(C1="","",1/C1)
-
WSXimon
AskWoody Lounger -
WSJohnBF
AskWoody Lounger -
WSXimon
AskWoody Lounger -
WSJohnBF
AskWoody LoungerOctober 26, 2001 at 9:00 pm #548852You would use similar construction, except you have to check on the #N/A status cell by cell:
For Each rngCell In Selection.SpecialCells(xlCellTypeFormulas, xlErrors)
If rngCell.Value = CVErr(xlErrNA) ThenEnd If
Next rngCellDo you want a routine that only looks for functions that evaluate to #N/A and deletes them, or do you want a routine that includes the deletion of cells in columns A & B routine we already have, and if so do you want the #N/A formula cell in column C also deleted?
-
H. Legare Coleman
AskWoody Plus -
WSWassim
AskWoody LoungerOctober 24, 2001 at 6:25 pm #548436Ximon
There is a better solution, faster and easier:
OK the formula you would use is like this: =IF(C1=””,1/0,C1) You would fill this formula down to all the rows with data.
Now this formula will produce an error (#DIV/0!) where cell in C is empty.
Then you would need to delete these formulas:
Select columns A and B and Press F5 to activate the GoTo
Then select special
From the dialog select Formulas and uncheck all but Errors.This will select all the cells with errors and then you simply hit the delete key and you are done.
Now if you need to do this many times, you would need to possibly automate it.
As Legare had mentioned, my code will miss some rows, so you would need to run it twice or even more. The use of a For-Next loop in this case is not the best way of doing things.
OK hope all of us have given you some starting points to get to your optimal solution.
Wassim
-
WSXimon
AskWoody Lounger
-
-
-
WSWassim
AskWoody LoungerOctober 24, 2001 at 6:03 pm #548429Ximon
Try this version then:
Sub DeleteBlankCells()
Dim lCounter As LongWith ActiveSheet
For lCounter = 2 To .Rows.Count
If Len(CStr(Range(“A” & lCounter).Value)) = 0 Then
‘/Cell is blanck so delete row.
.Range(“B” & lCounter).Resize(1, 2).Delete Shift:=xlUp
End If
Next lCounter
End With
End SubI also used the resize option here just to give you an example of how you can resize a range that you pick. But I am afraid that anytime you delete rows like that, the data may become skewed, that is the rows don’t match. I don’t know what the data you are working with looks like, but I need to caution you on this issue.
Wassim
-
-
H. Legare Coleman
AskWoody Plus -
WSWassim
AskWoody LoungerOctober 24, 2001 at 6:13 pm #548432 -
H. Legare Coleman
AskWoody Plus
-
-
-
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
-
X Suspends Encrypted DMs
by
Alex5723
56 minutes ago -
WSJ : My Robot and Me AI generated movie
by
Alex5723
1 hour, 14 minutes ago -
Botnet hacks 9,000+ ASUS routers to add persistent SSH backdoor
by
Alex5723
1 hour, 51 minutes ago -
OpenAI model sabotages shutdown code
by
Cybertooth
2 hours, 28 minutes ago -
Backup and access old e-mails after company e-mail address is terminated
by
M W Leijendekker
1 hour, 51 minutes ago -
Enabling Secureboot
by
ITguy
5 hours, 38 minutes ago -
Windows hosting exposes additional bugs
by
Susan Bradley
10 hours, 22 minutes ago -
No more rounded corners??
by
CWBillow
6 hours, 10 minutes ago -
Android 15 and IPV6
by
Win7and10
11 minutes ago -
KB5058405 might fail to install with recovery error 0xc0000098 in ACPI.sys
by
Susan Bradley
22 hours, 43 minutes ago -
T-Mobile’s T-Life App has a “Screen Recording Tool” Turned on
by
Alex5723
1 day, 1 hour ago -
Windows 11 Insider Preview Build 26100.4202 (24H2) released to Release Preview
by
joep517
19 hours, 59 minutes ago -
Windows Update orchestration platform to update all software
by
Alex5723
1 day, 8 hours ago -
May preview updates
by
Susan Bradley
20 hours, 7 minutes ago -
Microsoft releases KB5061977 Windows 11 24H2, Server 2025 emergency out of band
by
Alex5723
11 hours, 42 minutes ago -
Just got this pop-up page while browsing
by
Alex5723
1 day ago -
KB5058379 / KB 5061768 Failures
by
crown
22 hours ago -
Windows 10 23H2 Good to Update to ?
by
jkitc
11 minutes ago -
At last – installation of 24H2
by
Botswana12
2 days ago -
MS-DEFCON 4: As good as it gets
by
Susan Bradley
11 hours, 18 minutes ago -
RyTuneX optimize Windows 10/11 tool
by
Alex5723
2 days, 12 hours ago -
Can I just update from Win11 22H2 to 23H2?
by
Dave Easley
10 hours, 54 minutes ago -
Limited account permission error related to Windows Update
by
gtd12345
3 days, 1 hour ago -
Another test post
by
gtd12345
3 days, 2 hours ago -
Connect to someone else computer
by
wadeer
2 days, 20 hours ago -
Limit on User names?
by
CWBillow
2 days, 23 hours ago -
Choose the right apps for traveling
by
Peter Deegan
2 days, 13 hours ago -
BitLocker rears its head
by
Susan Bradley
1 day, 21 hours ago -
Who are you? (2025 edition)
by
Will Fastie
1 day, 20 hours ago -
AskWoody at the computer museum, round two
by
Will Fastie
2 days, 15 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.