Current location: Hot Scripts Forums » Programming Languages » Other Languages » Help with Macro to Delete Specific Sheets


Help with Macro to Delete Specific Sheets

Reply
  #1 (permalink)  
Old 02-18-09, 10:20 AM
DarleneMiles DarleneMiles is offline
Newbie Coder
 
Join Date: Jan 2009
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
Help with Macro to Delete Specific Sheets

I would like a macro to run through an entire spreadsheet and delete any tabs that have the text "GetRidOfMe" in cell IV65536. I thought it would look like the code below, but nothing happens. Help, please? (As you can see, I've commented out things I thought may have affected the macro, but they didn't. I would like to not have a prompt each time a sheet is being deleted.). Thank you so much!
Code:
Sub GetRidOfMe()
        
    Dim sh As Worksheet
 
    With Application
        .ScreenUpdating = False
        .EnableEvents = False
    End With
 
    For Each sh In ThisWorkbook.Worksheets
        If sh.Range("IV65536").Value = "GetRidOfMe" Then
'        Application.DisplayAlerts = False
        sh.Select

        sh.Delete
'        Application.DisplayAlerts = False
'        ActiveWindow.SelectedSheets.Delete
'        Application.DisplayAlerts = True
        End If
    Next sh

End Sub

Last edited by Nico; 02-18-09 at 10:51 AM. Reason: Wrappers.
Reply With Quote
  #2 (permalink)  
Old 02-19-09, 06:15 AM
Yeroon's Avatar
Yeroon Yeroon is offline
Code Master
 
Join Date: Aug 2007
Location: Netherlands, Nijmegen
Posts: 850
Thanks: 2
Thanked 20 Times in 20 Posts
Hi I tried it like this. First Macro to fill the sheet with the getridofme string. Second is you macro to delete any sheets with that string. If I just uncomment the displayalerts it gets deleted silently. So it should work.

Code:
Sub Macro2()
    For Each sh In ThisWorkbook.Worksheets
        sh.Range("IV65536").Value = "GetRidOfMe"
    Next sh
End Sub
You Macro

Code:
Sub Macro1()
'
' Macro1 Macro
' De macro is opgenomen op 19-2-2009 door Jeroen Penninx.
'

    Dim sh As Worksheet
 
    With Application
        .ScreenUpdating = False
        .EnableEvents = False
    End With
 
    For Each sh In ThisWorkbook.Worksheets
        If sh.Range("IV65536").Value = "GetRidOfMe" Then
        Application.DisplayAlerts = False
        sh.Select

        sh.Delete
'        Application.DisplayAlerts = False
'        ActiveWindow.SelectedSheets.Delete
'        Application.DisplayAlerts = True
        End If
    Next sh

End Sub
Are the sheets protected by any means maybe?

What happens if you add a MsgBox after the line For Each sh In ThisWorkbook.Worksheets

Code:
For Each sh In ThisWorkbook.Worksheets
   MsgBox "Got a worksheet to work with"
Get a MsgBox?
__________________
Feel free to thank people if they help you by clicking thanks at a post.
=================================
Make it idiot proof and someone will make a better idiot.
=================================
Realise the impotence of proof reading everything you publish
Reply With Quote
Reply

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
[SOLVED] Delete range of entries from database!! priyam ASP 1 09-29-08 01:11 PM
Delete range of entries from database!! priyam Database 2 09-23-08 03:03 AM
Automated macro sujata_ghosh Visual Basic 1 12-08-06 09:01 AM
Delete files/directories selected in MySQL ronlar PHP 3 08-08-05 08:41 AM
i know how to delete a file! but how to delete a directory? forcer JavaScript 3 01-28-04 07:00 AM


All times are GMT -5. The time now is 03:45 AM.
vBulletin® Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.