+ Reply to Thread
Results 1 to 3 of 3

VBA Delete a sheet based on cell value

  1. #1
    Registered User
    Join Date
    06-15-2011
    Location
    Converse, TX
    MS-Off Ver
    Excel 2016
    Posts
    72

    VBA Delete a sheet based on cell value

    As the title suggests, I am looking to delete a sheet(s) based on a single cell value. It's much simpler than it sounds, I assure you. However, despite its implicity I am still unable to figure out out to delete a single sheet based on the value of "A1".

    Essentially, my workbook has a bunch of sheets with various 4 digit numbers (ex 9481, 2789...). Ideally, what I would be able to do is to input the sheet that I am looking to remove by inputting it into cell A1.

  2. #2
    Registered User
    Join Date
    02-03-2016
    Location
    Australia
    MS-Off Ver
    2010
    Posts
    1

    Red face Re: VBA Delete a sheet based on cell value

    This may not be the most elegant, but it works.

    This assumes that the name of the sheet you want to delete is in cell A1

    Sub DeleteSheetA1()

    'deactivate alerts - stop 'are you sure you want to delete pop up'
    Application.DisplayAlerts = False

    'set worksheet you want to delete
    sheettodelete = Range("A1").Value

    'deletes sheet
    Worksheets(sheettodelete).Delete

    're-enable alerts
    Application.DisplayAlerts = True

    End Sub

    Hope that helps (this is my first post! woo)

  3. #3
    Registered User
    Join Date
    06-15-2011
    Location
    Converse, TX
    MS-Off Ver
    Excel 2016
    Posts
    72

    Re: VBA Delete a sheet based on cell value

    Quote Originally Posted by Melia*10 View Post
    This may not be the most elegant, but it works.

    This assumes that the name of the sheet you want to delete is in cell A1

    Sub DeleteSheetA1()

    'deactivate alerts - stop 'are you sure you want to delete pop up'
    Application.DisplayAlerts = False

    'set worksheet you want to delete
    sheettodelete = Range("A1").Value

    'deletes sheet
    Worksheets(sheettodelete).Delete

    're-enable alerts
    Application.DisplayAlerts = True

    End Sub

    Hope that helps (this is my first post! woo)
    It errors out at
    Please Login or Register  to view this content.
    The error message that I get says "Run-time Error '9': Subscript out of range."

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. [SOLVED] Delete entire row based on cell value in another sheet
    By DespoExcel in forum Excel Programming / VBA / Macros
    Replies: 15
    Last Post: 10-21-2014, 01:43 PM
  2. [SOLVED] Move entire row from one sheet to another based on cell value & delete the original row
    By ceciliacrawford in forum Excel Programming / VBA / Macros
    Replies: 8
    Last Post: 01-08-2014, 03:12 AM
  3. Replies: 2
    Last Post: 10-31-2013, 05:00 PM
  4. Cut/Delete row and paste to different sheet based on cell value in column
    By williamthomp in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 01-04-2013, 01:38 PM
  5. Macro to add sheet, name it based on previous sheet, and delete a range of cells
    By Moeshell in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 10-24-2011, 03:26 PM
  6. Copy row to another sheet and delete (based on cell content)
    By mpower87 in forum Excel Programming / VBA / Macros
    Replies: 13
    Last Post: 07-05-2010, 07:42 PM
  7. delete row(s) based on cell value in different sheet
    By MisterrMr in forum Excel Programming / VBA / Macros
    Replies: 8
    Last Post: 05-12-2010, 03:17 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1