How to delete rows and tabs

zombiemaster

Board Regular
Joined
Oct 27, 2009
Messages
241
I used to know some of this stuff but have been out of the VBA game for a few years...sorry to have to ask such a simple question!

I have a workbook that gets created each day with varying numbers of rows each day. Column C will have a numeric value. I need to delete all the rows with a numeric value greater than zero.

I currently do this manually by sorting A>Z, find the first row in the list with a number greater than zero, then deleting all the rows below that, but want to include VBA to do this step for me.

ALSO, there are multiple tabs in the workbook, and I delete all of them except the first tab. Is there a way to delete all the tabs except the first one named "Original Data"?

Thanks for your help,
-=ZM=-
 
Two codes below. The first deletes all sheets except the first. The second code deletes all sheets except "Original Data". Second would be safest I would say in case the order of sheets happens to have been changed.

VBA Code:
Sub DeleteSheets_1()
  Dim i As Long
 
  Application.DisplayAlerts = False
    For i = Sheets.Count To 2 Step -1
      Sheets(i).Delete
    Next i
  Application.DisplayAlerts = True
End Sub

Sub DeleteSheets_2()
  Dim ws As Worksheet
 
  Application.DisplayAlerts = False
    For Each ws In Worksheets
      If ws.Name <> "Original Data" Then ws.Delete
    Next ws
  Application.DisplayAlerts = True
End Sub
Perfect! I was able to incorporate both sets of your code into my existing VBA and run it without any issues (had to eliminate one Dim WS, but that was to be expected). Thanks so much, this would have taken me all day to figure out!

-=ZM=-
:cool:
 
Upvote 0

Excel Facts

Highlight Duplicates
Home, Conditional Formatting, Highlight Cells, Duplicate records, OK to add pink formatting to any duplicates in selected range.

Forum statistics

Threads
1,214,943
Messages
6,122,370
Members
449,080
Latest member
Armadillos

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top