?
Solved

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

Posted on 2014-11-06
6
Medium Priority
?
1,529 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
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
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 2000 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

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

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

This article will guide you to convert a grid from a picture into Excel format using Microsoft OneNote and no other 3rd party application.
When you see single cell contains number and text, and you have to get any date out of it seems like cracking our heads.
The viewer will learn how to use the =DISCRINV command to create a discrete random variable, use this command to model a set of probabilities and outcomes in a Monte Carlo simulation, and learn how to find the standard deviation of a set of probabil…
Many functions in Excel can make decisions. The most simple of these is the IF function: it returns a value depending on whether a condition you describe is true or false. Once you get the hang of using the IF function, you will find it easier to us…

752 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