Results 1 to 3 of 3

Thread: Undo operation in Excel

  1. #1
    New Member
    Join Date
    Dec 04
    Posts
    8

    Exclamation Undo operation in Excel

    Hi Guys

    Currently at work I am working on a large spreadsheet with many sheets (over 100). On each sheet there is a command button which, when pressed, takes you to an instruction sheet, and I wish to have a command button on the instruction sheet which will take you back to the last active sheet.

    Does anyone know a way of doing this?

    Any help will be greatly appreciated

    Thanks

  2. #2
    Hyperactive Member
    Join Date
    Aug 02
    Location
    UK
    Posts
    417

    Re: Undo operation in Excel

    Well I do not use Excel my self but Have you looked up on using Macros.
    did find a link on google tho I not sure if it what you want.

    Beginning Excel Reversing an Edit Operation
    http://helpdesk.fsu.edu/training/cou...uts/excel1.pdf

    anyway that about all I can help you with.
    When your dreams come true.
    On error resume pulling hair out.

  3. #3
    Super Moderator si_the_geek's Avatar
    Join Date
    Jul 02
    Location
    Bristol, UK
    Posts
    35,562

    Re: Undo operation in Excel

    For that you need to keep track of the previously active sheet, and to do this you can make use of the SheetActivate event of the Workbook, which passes a reference to the newly activated sheet.

    You need to store this and the previous value, so that you can activate the appropriate sheet. Here is some code to go in the Wokbook to store those values:
    VB Code:
    1. Dim oCurrSheet As Worksheet
    2. Dim oPrevSheet As Worksheet
    3.  
    4. Private Sub Workbook_SheetActivate(ByVal Sh As Object)
    5.  
    6.   Set oPrevSheet = oCurrSheet
    7.   Set oCurrSheet = Sh
    8.  
    9. End Sub
    In order to activate the previous sheet you just need oPrevSheet.Activate, however this will fire the SheetActivate event again - so then the previous sheet is where you just came from.

    If this is a problem, you need to make amendments like this (you now need to call ActivatePrevSheet instead):
    VB Code:
    1. Dim oCurrSheet As Worksheet
    2. Dim oPrevSheet As Worksheet
    3. Dim bIsActivating As Boolean
    4.  
    5. Sub ActivatePrevSheet()
    6.  
    7.   bIsActivating = True
    8.   oPrevSheet.Activate
    9.   bIsActivating = False
    10.  
    11. End Sub
    12.  
    13. Private Sub Workbook_SheetActivate(ByVal Sh As Object)
    14.  
    15.   If Not (bIsActivating) Then
    16.     Set oPrevSheet = oCurrSheet
    17.     Set oCurrSheet = Sh
    18.   End If
    19.  
    20. End Sub

Posting Permissions

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