Solved

Excel VBA Delete rows if condition is met and delete sheet

Posted on 2014-11-06
6
366 Views
Last Modified: 2014-11-06
please see attached worksheet.

i need help with VBA that when i run it, it would first delete sheet which its name is "OUTLINE" then activate the sheet named "MAIN" and check the column E and if the value is "Opening" then delete the entire row. basically as you can see that in the attached sheet there are 16 Rows that have value of "Opening" in the column of E and therefore all of those rows needs to be deleted.

thanks.
EE.xlsm
0
Comment
Question by:Flora
  • 3
  • 2
6 Comments
 
LVL 32

Expert Comment

by:Rob Henson
ID: 40426414
You can use AutoFilter to select rows containing a particular value.

When a Filter is active, any deletions (contents or whole rows) will only affect the visible rows.

Thanks
Rob H
0
 
LVL 6

Author Comment

by:Flora
ID: 40426427
Thank you Rob.

but i need this to be done by VBA, becuase my data is huge and select them and then deleting them with filter will take alot of time.

i want a simple VBA solution that can delete the worksheet named Outline and then delete rows from sheet MAIN that contain Opening in column E.
0
 
LVL 32

Expert Comment

by:Rob Henson
ID: 40426447
Using Filter shouldn't take long.

Select cell within data
Activate Filter
Use dropdown in column E to choose "Opening"
Select first visible value
Press Shift & End & Down to select all rows
Delete rows
Confirm OK to delete

Thanks
Rob H
0
Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

 
LVL 24

Accepted Solution

by:
Phillip Burton earned 500 total points
ID: 40426458
Assuming you have up to 9999 rows in Main

Sub DeleteRows()
Application.DisplayAlerts = False
Sheets("Outline").Delete
Application.DisplayAlerts = True
Sheets("Main").Activate
For introw = 9999 To 1 Step -1
    If Cells(introw, 5) = "Opening" Then
        Rows(introw).Delete
    End If
Next
End Sub

Open in new window

0
 
LVL 6

Author Comment

by:Flora
ID: 40426464
Thank you Rob. i appreciate your help and willingness to support. however, just like i said before. i am dealing with hundreds of workbooks like this. so i rather have a solution with VBA that would help me just clicking once, instead of going through all the process referred above.
0
 
LVL 6

Author Closing Comment

by:Flora
ID: 40426469
Thank you Philip

this is great.
0

Featured Post

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

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

Suggested Solutions

INDEX and MATCH can be used to great effect to replace HLOOKUP and VLOOKUP as it does not have the limitation of needing the data to be sorted so that the reference value is in the first column or row. It also has the ability to perform a bi-directi…
Some code to ensure data integrity when using macros within Excel. Also included code that helps secure your data within an Excel workbook.
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…
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.

816 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

9 Experts available now in Live!

Get 1:1 Help Now