Solved

Excel VBA Delete rows if condition is met and delete sheet

Posted on 2014-11-06
6
367 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 33

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 33

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
Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
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

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

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…
Workbook link problems after copying tabs to a new workbook? David Miller (dlmille) Intro Have you either copied sheets to a new workbook, and after having saved and opened that workbook, you find that there are links back to the original sou…
The viewer will learn how to create a normally distributed random variable in Excel, use a normal distribution to simulate the return on an investment over a period of years, Create a Monte Carlo simulation using a normal random variable, and calcul…
This Micro Tutorial will demonstrate how to use longer labels with horizontal bar charts instead of the vertical column chart.

861 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