Solved

Excel VBA Delete rows if condition is met and delete sheet

Posted on 2014-11-06
6
386 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
[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
  • 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
Online Training Solution

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action. Forget about retraining and skyrocket knowledge retention rates.

 
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

[Webinar] Learn How Hackers Steal Your Credentials

Do You Know How Hackers Steal Your Credentials? Join us and Skyport Systems to learn how hackers steal your credentials and why Active Directory must be secure to stop them. Thursday, July 13, 2017 10:00 A.M. PDT

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.
In Part II of this series, I will discuss how to identify all open instances of Excel and enumerate the workbooks, spreadsheets, and named ranges within each of those instances.
This Micro Tutorial demonstrates using Microsoft Excel pivot tables, how to reverse engineer competitors' marketing strategies through backlinks.
This Micro Tutorial will demonstrate how to use longer labels with horizontal bar charts instead of the vertical column chart.

724 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