+ Reply to Thread
Results 1 to 12 of 12

command button to return to active work sheet (SOLVED)

  1. #1
    Registered User
    Join Date
    10-24-2018
    Location
    sunderland
    MS-Off Ver
    Microsoft? Excel? for Microsoft 365 MSO (Version 2404 Build 16.0.17531.20152) 64-bit
    Posts
    72

    command button to return to active work sheet (SOLVED)

    hi all

    I have a work planner with 52 weeks in it,

    I have a command button that allows me to go from the work planner to another sheet containing a holiday planner

    I would like to add a command button on the holiday planner to take me back to the last active sheet i had been working in before selecting the go to holiday planner cmd button

    is this possible and how would I go about it

    (im still very new to VBA and macros)

    thanks

    Andy
    Last edited by sharky1978; 12-19-2018 at 09:15 AM.

  2. #2
    Valued Forum Contributor dmcgov's Avatar
    Join Date
    11-11-2015
    Location
    Florida, USA
    MS-Off Ver
    Office 365 Business
    Posts
    1,518

    Re: command button to return to active work sheet

    review this link, that should get you going. if not, let me know

    https://www.extendoffice.com/documen...ive-sheet.html

  3. #3
    Forum Expert PaulM100's Avatar
    Join Date
    10-09-2017
    Location
    UK
    MS-Off Ver
    Office 365
    Posts
    2,108

    Re: command button to return to active work sheet

    Or check this link https://www.mrexcel.com/forum/excel-...worksheet.html
    Click the * to say thanks.

  4. #4
    Registered User
    Join Date
    10-24-2018
    Location
    sunderland
    MS-Off Ver
    Microsoft? Excel? for Microsoft 365 MSO (Version 2404 Build 16.0.17531.20152) 64-bit
    Posts
    72

    Re: command button to return to active work sheet

    hi paul
    I have followed the instructions on the link but I cant work out what I have done wrong I keep getting, the error message then the cmd button wont do anything

    the error message is "You have not switched sheets yet since opening the file!"

  5. #5
    Forum Expert PaulM100's Avatar
    Join Date
    10-09-2017
    Location
    UK
    MS-Off Ver
    Office 365
    Posts
    2,108

    Re: command button to return to active work sheet

    This means that you have not switched the sheets.

  6. #6
    Registered User
    Join Date
    10-24-2018
    Location
    sunderland
    MS-Off Ver
    Microsoft? Excel? for Microsoft 365 MSO (Version 2404 Build 16.0.17531.20152) 64-bit
    Posts
    72

    Re: command button to return to active work sheet

    if I switch sheets the cmd button wont do anything when I go back in, and that message will not appear again

    I think I have put the public variable in the wrong place, im still very new to vba so going to check I did the first part correctly

  7. #7
    Forum Expert PaulM100's Avatar
    Join Date
    10-09-2017
    Location
    UK
    MS-Off Ver
    Office 365
    Posts
    2,108

    Re: command button to return to active work sheet

    Upload a sample file and your current code. This will be the easiest way to get a solution

  8. #8
    Registered User
    Join Date
    10-24-2018
    Location
    sunderland
    MS-Off Ver
    Microsoft? Excel? for Microsoft 365 MSO (Version 2404 Build 16.0.17531.20152) 64-bit
    Posts
    72

    Re: command button to return to active work sheet

    ""Public MyPrevSheet As String


    Private Sub Workbook_SheetDeactivate(ByVal Sh As Object)
    MyPrevSheet = Sh.Name
    End Sub

    Sub GoToPreviousSheet()

    If Len(MyPrevSheet) > 0 Then
    Sheets(MyPrevSheet).Activate
    Else
    MsgBox "You have not switched sheets yet since opening the file!"
    End If

    End Sub
    "
    im not sure how to add the code to the post correctly sorry

  9. #9
    Registered User
    Join Date
    10-24-2018
    Location
    sunderland
    MS-Off Ver
    Microsoft? Excel? for Microsoft 365 MSO (Version 2404 Build 16.0.17531.20152) 64-bit
    Posts
    72

    Re: command button to return to active work sheet

    I also tried

    Private Sub CommandButton1_Click()

    End Sub

    Sub GoToPreviousSheet()

    If Len(MyPrevSheet) > 0 Then
    Sheets(MyPrevSheet).Activate
    Else
    MsgBox "You have not switched sheets yet since opening the file!"
    End If

    End Sub

  10. #10
    Forum Expert PaulM100's Avatar
    Join Date
    10-09-2017
    Location
    UK
    MS-Off Ver
    Office 365
    Posts
    2,108

    Re: command button to return to active work sheet

    Ok, try this:

    Add the code below into ThisWorkbook module in VBA. Double click and paste it
    Please Login or Register  to view this content.
    Into a standard module add this code:
    Please Login or Register  to view this content.
    Create a button using Insert - Shapes and assign the code to it like: Right click - assign macro - SelectLastActive

  11. #11
    Registered User
    Join Date
    10-24-2018
    Location
    sunderland
    MS-Off Ver
    Microsoft? Excel? for Microsoft 365 MSO (Version 2404 Build 16.0.17531.20152) 64-bit
    Posts
    72

    Re: command button to return to active work sheet

    lol your awesome cheers Paul

    why cant they make it that easy on them help websites

  12. #12
    Forum Expert PaulM100's Avatar
    Join Date
    10-09-2017
    Location
    UK
    MS-Off Ver
    Office 365
    Posts
    2,108

    Re: command button to return to active work sheet

    Glad to help. Please mark the thread as Solved if that took care of your solution.
    Also, each user may have a different problem/solution/approach, therefore the difficulty.

+ 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] Create command button to return to the previous active sheet
    By elizevonne in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 01-31-2015, 05:01 AM
  2. VBA - Command button to transfer data to a new work sheet.
    By liamhenderson in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 12-02-2013, 04:10 AM
  3. How to dissable active X command button on sheet
    By GavJ in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 10-18-2013, 07:09 AM
  4. Copy active sheet to a new workbook, close that work book and return
    By nig_44 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 03-30-2012, 02:24 AM
  5. Tab sequence from cell to active x button and then to a command button
    By 2funny4words in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 07-07-2009, 02:27 PM
  6. Command button - to copy active sheet and not save current workbook
    By vjboaz in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 01-22-2008, 05:23 PM
  7. Printing Active Sheet with command button
    By iturnrocks in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 01-19-2007, 03:53 AM

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