+ Reply to Thread
Results 1 to 5 of 5

Deleting a sheet via code-- different criteria

  1. #1
    KimberlyC
    Guest

    Deleting a sheet via code-- different criteria

    Hi Again...

    I've thought of a better way to remove unwanted worksheets from my
    workbook....

    I need to run code that will delete all worksheets in my activeworkbook that
    have "Delete" in cell A3 of the worksheet.
    Cell A3 has a formula in it of each worksheet that determines if the sheet
    needs to be deleted or not... if it needs to be deleted.. then, the formula
    returns "delete"...otherwise..it's blank "".


    I think this will work better than my previous post......


    I'm not sure how to do this ... so any help is greatly appreciated..

    Thanks in advance,
    Kimberly



  2. #2
    Kim
    Guest

    Re: Deleting a sheet via code-- different criteria

    sub test
    dim sht as sheet
    for each sht in activeworkbook
    if sht.range("A3")="delete" then
    sht.delete
    end if
    next
    end sub


    "KimberlyC" <[email protected]> wrote in message
    news:[email protected]...
    > Hi Again...
    >
    > I've thought of a better way to remove unwanted worksheets from my
    > workbook....
    >
    > I need to run code that will delete all worksheets in my activeworkbook

    that
    > have "Delete" in cell A3 of the worksheet.
    > Cell A3 has a formula in it of each worksheet that determines if the sheet
    > needs to be deleted or not... if it needs to be deleted.. then, the

    formula
    > returns "delete"...otherwise..it's blank "".
    >
    >
    > I think this will work better than my previous post......
    >
    >
    > I'm not sure how to do this ... so any help is greatly appreciated..
    >
    > Thanks in advance,
    > Kimberly
    >
    >




  3. #3
    Bob Phillips
    Guest

    Re: Deleting a sheet via code-- different criteria

    Don't forget to set

    Application.DisplayALerts = False

    to avoid the warning, and reset at the end.

    --

    HTH

    RP
    (remove nothere from the email address if mailing direct)


    "Kim" <[email protected]> wrote in message
    news:[email protected]...
    > sub test
    > dim sht as sheet
    > for each sht in activeworkbook
    > if sht.range("A3")="delete" then
    > sht.delete
    > end if
    > next
    > end sub
    >
    >
    > "KimberlyC" <[email protected]> wrote in message
    > news:[email protected]...
    > > Hi Again...
    > >
    > > I've thought of a better way to remove unwanted worksheets from my
    > > workbook....
    > >
    > > I need to run code that will delete all worksheets in my activeworkbook

    > that
    > > have "Delete" in cell A3 of the worksheet.
    > > Cell A3 has a formula in it of each worksheet that determines if the

    sheet
    > > needs to be deleted or not... if it needs to be deleted.. then, the

    > formula
    > > returns "delete"...otherwise..it's blank "".
    > >
    > >
    > > I think this will work better than my previous post......
    > >
    > >
    > > I'm not sure how to do this ... so any help is greatly appreciated..
    > >
    > > Thanks in advance,
    > > Kimberly
    > >
    > >

    >
    >




  4. #4
    Forum Contributor
    Join Date
    02-26-2005
    Posts
    175
    Kim,
    I tried your code and it would stop at the second and third line.
    I had to change them to make it work. After i changed them it worked fine.
    My question is:
    Why and what is the difference, between the two statements?
    What is the difference between Sheet and Worksheet?

    The red is what i changed them to.
    sub test
    'dim sht as sheet
    Dim sht As Worksheet
    'for each sht in activeworkbook
    For Each sht In ActiveWorkbook.Worksheets
    if sht.range("A3")="delete" then
    sht.delete
    end if
    next

    Thx
    Dave
    Quote Originally Posted by Kim
    sub test
    dim sht as sheet
    for each sht in activeworkbook
    if sht.range("A3")="delete" then
    sht.delete
    end if
    next
    end sub


    "KimberlyC" <[email protected]> wrote in message
    news:[email protected]...
    > Hi Again...
    >
    > I've thought of a better way to remove unwanted worksheets from my
    > workbook....
    >
    > I need to run code that will delete all worksheets in my activeworkbook

    that
    > have "Delete" in cell A3 of the worksheet.
    > Cell A3 has a formula in it of each worksheet that determines if the sheet
    > needs to be deleted or not... if it needs to be deleted.. then, the

    formula
    > returns "delete"...otherwise..it's blank "".
    >
    >
    > I think this will work better than my previous post......
    >
    >
    > I'm not sure how to do this ... so any help is greatly appreciated..
    >
    > Thanks in advance,
    > Kimberly
    >
    >

  5. #5
    STEVE BELL
    Guest

    Re: Deleting a sheet via code-- different criteria

    I got caught by this the other day -

    Sheets includes worksheets and chart sheets

    Worksheets doesn't include chart sheets.
    --
    steveB

    Remove "AYN" from email to respond
    "Piranha" <[email protected]> wrote in
    message news:[email protected]...
    >
    > Kim,
    > I tried your code and it would stop at the second and third line.
    > I had to change them to make it work. After i changed them it worked
    > fine.
    > My question is:
    > Why and what is the difference, between the two statements?
    > What is the difference between Sheet and Worksheet?
    >
    > The red is what i changed them to.
    > sub test
    > 'dim sht as sheet
    > Dim sht As Worksheet
    > 'for each sht in activeworkbook
    > For Each sht In ActiveWorkbook.Worksheets
    > if sht.range("A3")="delete" then
    > sht.delete
    > end if
    > next
    >
    > Thx
    > Dave
    > Kim Wrote:
    >> sub test
    >> dim sht as sheet
    >> for each sht in activeworkbook
    >> if sht.range("A3")="delete" then
    >> sht.delete
    >> end if
    >> next
    >> end sub
    >>
    >>
    >> "KimberlyC" <[email protected]> wrote in message
    >> news:[email protected]...
    >> > Hi Again...
    >> >
    >> > I've thought of a better way to remove unwanted worksheets from my
    >> > workbook....
    >> >
    >> > I need to run code that will delete all worksheets in my

    >> activeworkbook
    >> that
    >> > have "Delete" in cell A3 of the worksheet.
    >> > Cell A3 has a formula in it of each worksheet that determines if the

    >> sheet
    >> > needs to be deleted or not... if it needs to be deleted.. then, the

    >> formula
    >> > returns "delete"...otherwise..it's blank "".
    >> >
    >> >
    >> > I think this will work better than my previous post......
    >> >
    >> >
    >> > I'm not sure how to do this ... so any help is greatly appreciated..
    >> >
    >> > Thanks in advance,
    >> > Kimberly
    >> >
    >> >

    >
    >
    > --
    > Piranha
    > ------------------------------------------------------------------------
    > Piranha's Profile:
    > http://www.excelforum.com/member.php...o&userid=20435
    > View this thread: http://www.excelforum.com/showthread...hreadid=386308
    >




+ Reply to Thread

Thread Information

Users Browsing this Thread

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

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