+ Reply to Thread
Results 1 to 6 of 6

Worksheet does not become the active 1 using .Activate function based on MsgBox response

Hybrid View

  1. #1
    Registered User
    Join Date
    03-27-2013
    Location
    Long Island, NY
    MS-Off Ver
    Excel 2007
    Posts
    35

    Worksheet does not become the active 1 using .Activate function based on MsgBox response

    I do not see what is going wrong here.
    Before the user runs the macro, they are supposed to use the autofilter on the "Project" tab to determine which #'s they would like to sort the data by.
    I have put a message box in, in case the user forgot to do that.
    If they select "No", exit the sub and have the active sheet be the "Project" tab.
    If "Yes" just run the macro(which works).

    I cannot get the "Project" tab to be the sheet shown if "No" is clicked.
    Any advice?

    *edit: it always goes to the "SC" tab instead
    Below is my macro:

    Sub Project()
    Dim Response As Boolean
    'Make sure user has selected Project numbers from the Project tab.
    Response = MsgBox("Did you select which Project(s) you want to sort by in the Project tab?", vbYesNo, "Project Sort")
    'If they have not, make the Project tab shown and exit the sub. 
    If Response = vbNo Then
    Worksheets("Project").Activate  
    
    Exit Sub
    
    End If
    
    With Application
    
            .Calculation = xlCalculationManual
    
            .ScreenUpdating = False
    '-------------------------------------------------------------------------
    'DM Project # Search.
    Dim lastrowProject As Long
    lastrowProject = Worksheets("Project").Cells(Rows.Count, 1).End(xlUp).Row
    Sheets("DM").Select
    Columns("O:O").AdvancedFilter Action:=xlFilterInPlace, CriteriaRange:= _
            Sheets("Project").Range("A1", Sheets("Project").Range("A" & lastrowProject)), Unique:=False
      
    
    '------------------------------------------------------------------------------
    'SC Project # Search.
    lastrowProject = Worksheets("Project").Cells(Rows.Count, 1).End(xlUp).Row
    Sheets("SC").Select
    Columns("O:O").AdvancedFilter Action:=xlFilterInPlace, CriteriaRange:= _
            Sheets("Project").Range("A1", Sheets("Project").Range("A" & lastrowProject)), Unique:=False
    
    
            .Calculation = xlCalculationAutomatic
    
            .ScreenUpdating = True
    
        End With
    End Sub

  2. #2
    Forum Contributor
    Join Date
    01-02-2007
    Location
    Australia NSW
    MS-Off Ver
    2013
    Posts
    494

    Re: Worksheet does not become the active 1 using .Activate function based on MsgBox respon

    If the tab 'Project' is hidden, then you need to add:
    Sheets("Project").Visible=True
    before Activating it.

  3. #3
    Registered User
    Join Date
    03-27-2013
    Location
    Long Island, NY
    MS-Off Ver
    Excel 2007
    Posts
    35

    Re: Worksheet does not become the active 1 using .Activate function based on MsgBox respon

    It is not hidden.

  4. #4
    Forum Contributor
    Join Date
    01-03-2013
    Location
    Aberdeen, Scotland
    MS-Off Ver
    Excel 2007
    Posts
    163

    Re: Worksheet does not become the active 1 using .Activate function based on MsgBox respon

    I would say it's because Response is declared as Boolean and thus can only have two values: True or False, so it won't accept vbNo. Change Response variable to be as String and it should work. But this is only my opinion

  5. #5
    Registered User
    Join Date
    03-27-2013
    Location
    Long Island, NY
    MS-Off Ver
    Excel 2007
    Posts
    35

    Re: Worksheet does not become the active 1 using .Activate function based on MsgBox respon

    Sbarro79, thank you very much! works like a charm

  6. #6
    Forum Contributor
    Join Date
    01-02-2007
    Location
    Australia NSW
    MS-Off Ver
    2013
    Posts
    494

    Re: Worksheet does not become the active 1 using .Activate function based on MsgBox respon

    Also, Change:
    Dim Response As Boolean
    to:
    Dim Res As Boolean
    Some words do not work effectively when declared, and try Variant instead of Boolean.

+ 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] Msgbox with if condition based on date of worksheet
    By nickmax1 in forum Excel Programming / VBA / Macros
    Replies: 22
    Last Post: 04-30-2013, 05:48 AM
  2. Replies: 1
    Last Post: 12-03-2012, 08:55 AM
  3. Stop Input into Worksheet Based on Yes No Response
    By fmluder93 in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 03-09-2009, 03:38 AM
  4. [SOLVED] Activate a Worksheet from a Custom Function ??
    By monir in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 05-17-2005, 02:06 PM
  5. MsgBox response
    By Sunflower_Queen in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 01-13-2005, 05:08 PM

Tags for this Thread

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