+ Reply to Thread
Results 1 to 3 of 3

VBA Code to delete sheets based on lists

  1. #1
    Registered User
    Join Date
    03-23-2015
    Location
    Luxembourg
    MS-Off Ver
    2007
    Posts
    2

    VBA Code to delete sheets based on lists

    Hello All:


    I have a list of sheets that I would like to delete from a current workbook. The list is in a sheet named "Funds" in the column A. I would like to write VBA code to delete sheets based on whether or not the names are on this sheet "Funds".

    Thank you all for you help in advance. The code which I`m using is below however it does not do anything, have no idea why.


    Sub DeleteSheets()

    Dim wks As Worksheet
    Dim MyRange As Range
    Dim Cell As Range

    Set wks = Worksheets("Funds")

    With wks
    Set MyRange = Range("A1", .Cells(.Rows.Count, "A").End(xlUp))
    End With

    On Error Resume Next
    Application.DisplayAlerts = False
    For Each Cell In MyRange
    Sheets(Cell.Value).Delete
    Next Cell
    Application.DisplayAlerts = True
    On Error GoTo 0

    End Sub
    Attached Files Attached Files
    Last edited by Anush.Seyranyan; 03-23-2015 at 11:07 AM.

  2. #2
    Forum Contributor
    Join Date
    06-09-2011
    Location
    Germany
    MS-Off Ver
    Excel 2016
    Posts
    194

    Re: VBA Code to delete sheets based on lists

    Hi Anush,

    your code did not actually delete sheets but deleted entries from your funds table. The following code should work:

    Please Login or Register  to view this content.
    Let me know if this works for you.

    Theo
    Remember To Do the Following....
    1. Upload sample files
    2. Thank those who have helped you by clicking the Star below the post.
    3. Please mark your post [SOLVED] if it has been answered satisfactorily.

  3. #3
    Registered User
    Join Date
    03-23-2015
    Location
    Luxembourg
    MS-Off Ver
    2007
    Posts
    2

    Re: VBA Code to delete sheets based on lists

    Hi Theo,

    thank you very much. Yes it has worked

+ 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] Hide and delete sheets based on cell input
    By kokjinq in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 08-11-2014, 11:37 PM
  2. [SOLVED] VBA code to hide/unhide sheets based on a tick-box (TRUE/FALSE)
    By kavindra in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 01-10-2013, 08:11 AM
  3. Hide and Unhide sheets based on Date [better code]
    By Deryl in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 10-30-2012, 09:22 AM
  4. Hide/Unhide rows Based on Value from Dropdown Lists
    By 2Deep in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 12-12-2010, 09:43 PM
  5. Delete Columns and hide sheets
    By dodom75 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 07-08-2008, 04:55 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