Solved

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

Posted on 2014-11-06
6
1,428 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 3
6 Comments
 
LVL 15

Expert Comment

by:Haris Djulic
ID: 40427641
No attachment
0
 
LVL 1

Author Comment

by:xllvr
ID: 40427643
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
ID: 40427657
In your question you are saying " Attached is a sample of the data I'm cleaning up. " but no attachment is there...
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 1

Author Comment

by:xllvr
ID: 40427661
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
ID: 40427671
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
ID: 40427675
That worked beautifully!  Thanks so much for a great solution, Haris.  I'm so appreciative.
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Excel can be a tricky bit of software to get your head around. Whilst you’ll be able to eventually get to grips with the basic understanding of how to get by, there are a few Excel tips that not everybody will even know about let alone know how to d…
Do you use a spreadsheet like Microsoft's Excel?  Have you ever wanted to link out to a non excel file on your computer or network drive?  This is the way I found to do it!
This Micro Tutorial demonstrates in Microsoft Excel how to consolidate your marketing data by creating an interactive charts using form controls. This creates cool drop-downs for viewers of your chart to choose from.
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…

740 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