Solved

Excel vba - If  cells in multiple columns are empty, delete row

Posted on 2014-11-06
6
1,297 Views
Last Modified: 2014-11-06
Hello Experts!

Attached is a sample of the data I'm cleaning up.  I'll need to delete rows whenever the corresponding cells in Columns B:E are empty.  I have highlighted in yellow what satisfies that condition.  

I would very much appreciate your help with code to delete rows where the cells in B:E are empty.

Thank you!
0
Comment
Question by:xllvr
  • 3
  • 3
6 Comments
 
LVL 15

Expert Comment

by:Haris Djulic
Comment Utility
No attachment
0
 
LVL 1

Author Comment

by:xllvr
Comment Utility
Hi Haris,

I don't see a post or an attachment here.  Were you intending to comment?
0
 
LVL 15

Expert Comment

by:Haris Djulic
Comment Utility
In your question you are saying " Attached is a sample of the data I'm cleaning up. " but no attachment is there...
0
IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 
LVL 1

Author Comment

by:xllvr
Comment Utility
Oh no!  So strange...I attached it but failed to hit upload earlier.  Apologies!

Here you go.
EE-Delete-Row-Test.xlsm
0
 
LVL 15

Accepted Solution

by:
Haris Djulic earned 500 total points
Comment Utility
Hello,

here is the code:
Private Sub CommandButton1_Click()

i = 1
j = ActiveSheet.Cells(ActiveSheet.Rows.Count, "A").End(xlUp).Row
Do While i < j
If i = 0 Then i = 1

If ActiveSheet.Range("B" & i).Value = "" And ActiveSheet.Range("C" & i).Value = "" And ActiveSheet.Range("D" & i).Value = "" And ActiveSheet.Range("E" & i).Value = "" Then
ActiveSheet.Rows(i).Delete
i = i - 1
j = j - 1
Else
i = i + 1
End If

Loop

End Sub

Open in new window


Attached is the sample file without empty lines.. Just replicate it to your copy of file...
EE-Delete-Row-Test.xlsm
0
 
LVL 1

Author Closing Comment

by:xllvr
Comment Utility
That worked beautifully!  Thanks so much for a great solution, Haris.  I'm so appreciative.
0

Featured Post

Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

Join & Write a Comment

Drop Down List with Unique/Distinct Values (enhancing the Combo-Box with a few steps and a little code) David miller (dlmille) Intro Have you ever created a data validation list from a database field or spreadsheet column (e.g., Zip Codes or Co…
Introduction This Article is a follow-up to my Mappit! Addin Article (http://www.experts-exchange.com/A_2613.html), it was inspired by an email posting I made to EUSPRIG (http://www.eusprig.org/index.htm), I will briefly cover: 1) An overvie…
This Micro Tutorial will demonstrate on a Mac how to change the sort order for chart legend values and decrpyt the intimidating chart menu.
This Micro Tutorial will demonstrate in Google Sheets how to use the HYPERLINK function to create live links inside your spreadsheet.

762 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now