Results 1 to 2 of 2

Thread: Deselect Sheets

  1. #1
    snax500
    Guest

    Deselect Sheets

    I have the following macro in Excel2000:

    For Each sht In ActiveWindow.SelectedSheets
    If Not sht.Range("b33") = "Test" Then
    sht.Deselect
    End If
    Next

    What I want this to do is, if "test" is not in cell b33 to deselect the sheet. Of course deselect is not the right method. How do I do this?

    Thanks

  2. #2
    WS Lounge VIP rory's Avatar
    Join Date
    Dec 2000
    Location
    Burwash, East Sussex, United Kingdom
    Posts
    6,280
    Thanks
    3
    Thanked 191 Times in 177 Posts

    Re: Deselect Sheets

    Hi,
    I approached this from a slightly different direction as there doesn't appear to be a Deselect or equivalent method as you noted. This code:
    Sub deselect()
    Dim sht As Worksheet, blnFirst As Boolean
    blnFirst = True
    For Each sht In ActiveWindow.SelectedSheets
    If sht.Range("A1") = "test" Then
    sht.Select blnFirst
    If blnFirst Then blnFirst = False
    End If
    Next 'sht
    End Sub
    checks each selected sheet for 'test' in A1, replaces the current selection with the first one it finds and then appends any others to the selection.
    Hope that helps.
    Regards,
    Rory

    Microsoft MVP - Excel

Posting Permissions

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