Solved

Excel VBA Delete rows if condition is met and delete sheet

Posted on 2014-11-06
6
361 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 31

Expert Comment

by:Rob Henson
Comment Utility
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 5

Author Comment

by:Flora
Comment Utility
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 31

Expert Comment

by:Rob Henson
Comment Utility
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
Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

 
LVL 24

Accepted Solution

by:
Phillip Burton earned 500 total points
Comment Utility
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 5

Author Comment

by:Flora
Comment Utility
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 5

Author Closing Comment

by:Flora
Comment Utility
Thank you Philip

this is great.
0

Featured Post

Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

Join & Write a Comment

A2 = A1 That kind of cell reference is relative.  If you copy it from A2 to B2, then B2 will get this: B2 = B1 That's all fine and good, but if you then insert a new row above row 2, you'll find: A3 = A1 B3 = B1 This is intentional. …
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 use a discrete random variable to simulate the return on an investment over a period of years, create a Monte Carlo simulation using the discrete random variable, and create a graph to represent the possible returns over…
This Micro Tutorial demonstrate the bugs in Microsoft Excel for Mac with Pivot Charts.

762 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