+ Reply to Thread
Results 1 to 8 of 8

condition fails. If condition deletes main worksheet

  1. #1
    Forum Contributor
    Join Date
    01-06-2017
    Location
    india
    MS-Off Ver
    2010
    Posts
    118

    condition fails. If condition deletes main worksheet

    hi,


    Sub deleteallsheetsexceptsheet4()
    Dim ws As Worksheet
    Application.DisplayAlerts = False
    For Each ws In ThisWorkbook.Worksheets
    If ws.name <> "sheet4" Then ( i also tried -- if not ws.name="Sheet4" then)
    ws.Delete
    End If
    Next ws
    Application.DisplayAlerts = True
    End Sub

    i think above code is correct. but , code is deleted "sheet4" also.
    Attached Files Attached Files
    Last edited by shiva_raj; 02-22-2017 at 10:45 AM.

  2. #2
    Valued Forum Contributor ImranBhatti's Avatar
    Join Date
    03-27-2014
    Location
    Rawalpindi,Pakistan
    MS-Off Ver
    Office 365
    Posts
    1,784

    Re: condition fails. If condition deletes main worksheet

    Try this
    Please Login or Register  to view this content.
    Teach me Excel VBA

  3. #3
    Forum Contributor
    Join Date
    01-06-2017
    Location
    india
    MS-Off Ver
    2010
    Posts
    118

    Re: condition fails. If condition deletes main worksheet

    it works perfectly. thank you very much. But , What is wrong in my code

  4. #4
    Valued Forum Contributor ImranBhatti's Avatar
    Join Date
    03-27-2014
    Location
    Rawalpindi,Pakistan
    MS-Off Ver
    Office 365
    Posts
    1,784

    Re: condition fails. If condition deletes main worksheet

    Line in your code
    Please Login or Register  to view this content.
    Line in corrected code
    Please Login or Register  to view this content.

  5. #5
    Forum Contributor
    Join Date
    01-06-2017
    Location
    india
    MS-Off Ver
    2010
    Posts
    118

    Re: condition fails. If condition deletes main worksheet

    Is "IF" condition always supports case sensitive?

  6. #6
    Valued Forum Contributor ImranBhatti's Avatar
    Join Date
    03-27-2014
    Location
    Rawalpindi,Pakistan
    MS-Off Ver
    Office 365
    Posts
    1,784

    Re: condition fails. If condition deletes main worksheet

    Yes sheet names are case sensitive.

  7. #7
    Forum Contributor
    Join Date
    01-06-2017
    Location
    india
    MS-Off Ver
    2010
    Posts
    118

    Re: condition fails. If condition deletes main worksheet

    thank you......

  8. #8
    Valued Forum Contributor ImranBhatti's Avatar
    Join Date
    03-27-2014
    Location
    Rawalpindi,Pakistan
    MS-Off Ver
    Office 365
    Posts
    1,784

    Re: condition fails. If condition deletes main worksheet

    You are welcome!


    And Shiva ji if the answer really takes care of your query ,please mark the thread as "Solved".

+ 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] Move to next file if condition fails
    By pratnimk in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 02-17-2017, 11:25 AM
  2. [SOLVED] Loops are driving me loopy! How to exit a loop as soon as condition fails
    By mc84excel in forum Excel Programming / VBA / Macros
    Replies: 22
    Last Post: 03-22-2016, 12:39 AM
  3. if with one main condition and two scenarios
    By OmarHamza in forum Excel Formulas & Functions
    Replies: 3
    Last Post: 02-02-2016, 05:34 AM
  4. [SOLVED] Help Edit Loop that deletes Rows based on Date condition.
    By swade730 in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 08-08-2015, 02:16 PM
  5. Select worksheet based on condition & populate cell based on condition
    By beth1069 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 11-19-2011, 01:27 PM
  6. Highlight data with some color if condition fails
    By jesika in forum Access Tables & Databases
    Replies: 2
    Last Post: 04-08-2009, 07:35 AM
  7. Replies: 2
    Last Post: 12-20-2005, 09:50 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