• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 416
  • Last Modified:

Excel VBA Delete rows if condition is met and delete sheet

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
Flora
Asked:
Flora
  • 3
  • 2
1 Solution
 
Rob HensonIT & Database AssistantCommented:
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
 
FloraAuthor Commented:
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
 
Rob HensonIT & Database AssistantCommented:
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
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 
Phillip BurtonDirector, Practice Manager and Computing ConsultantCommented:
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
 
FloraAuthor Commented:
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
 
FloraAuthor Commented:
Thank you Philip

this is great.
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

  • 3
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now