VBA code to delete sheet if contains cell with value > X

MinnState

New Member
Joined
Sep 11, 2018
Messages
2
Good afternoon,

I've reviewed many threads on how to delete a sheet if it contains a specific condition, but none that quite meets my needs.

I have a workbook with over 900 sheets. I need to run a script that can be run once to delete an entire sheet if cell T7 on that sheet has a value greater than $5,000. I've tried modifying code from other threads but it's clear I am off base.

Thanks for any help you can provide.

-E
 

Excel Facts

Format cells as time
Select range and press Ctrl+Shift+2 to format cells as time. (Shift 2 is the @ sign).
Hi & welcome to MrExcel.
How about
Code:
Sub DelSht()
   Dim Ws As Worksheet
   Application.DisplayAlerts = False
   For Each Ws In Worksheets
   Debug.Print Ws.Name
      If Ws.Range("T7").Value > 5000 Then Ws.Delete
   Next Ws
   Application.DisplayAlerts = True
End Sub
 
Upvote 0
Ugh 900 sheets??? ok I won't judge :-)
Anyhow...
On a new sheet maybe called Cleaner add a worksheet button and assign it to this macro:


Code:
Sub looper()


         ' Declare Current as a worksheet object variable.
         Dim Current As Worksheet
stimer = timer 'set timer
         ' Loop through all of the worksheets in the active workbook.
Application.StatusBar = "****Please Wait*****  Macro processing"
Application.DisplayAlerts = False
Application.ScreenUpdating = False
         For Each Current In Worksheets
            ' Insert your code here.
     if current.range("T7")>5000 then
current.delete
endif      
         Next
Application.ScreenUpdating = True
Application.DisplayAlerts = True
Application.StatusBar = False
msgbox "Completed in " & round(timer-stimer),2) & " seconds."
      End Sub
 
Upvote 0
Glad we could help & thanks for the feedback
 
Upvote 0

Forum statistics

Threads
1,223,970
Messages
6,175,699
Members
452,667
Latest member
vanessavalentino83

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