Consulting

Results 1 to 11 of 11

Thread: Solved: Jump to last worksheet

  1. #1
    VBAX Mentor
    Joined
    Oct 2007
    Posts
    372
    Location

    Solved: Jump to last worksheet

    We all know ctrl + pg dn / pg up cyles up and down through sheets. Is there anyway to assign a short cut like ctrl alt a or something to jump to between the last and current work sheets? The reason for wanting to do this would be to skip and the ctrl dn'ing and up'ing and not being able to simply move the sheets closer together.

  2. #2
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    [vba]

    Public Sub Test()

    Application.OnKey "^%{PGUP}", "FirstSheet" 'Ctrl-Alt-PageUp
    Application.OnKey "^%{PGDN}", "LastSheet" 'Ctrl-Alt-PageDown
    End Sub


    Sub FirstSheet()
    ActiveWorkbook.Worksheets(1).Select
    End Sub

    Sub LastSheet()
    ActiveWorkbook.Worksheets(ActiveWorkbook.Worksheets.Count).Select
    End Sub
    [/vba]
    ____________________________________________
    Nihil simul inventum est et perfectum

    Abusus non tollit usum

    Last night I dreamed of a small consolation enjoyed only by the blind: Nobody knows the trouble I've not seen!
    James Thurber

  3. #3
    VBAX Mentor
    Joined
    Oct 2007
    Posts
    372
    Location
    Where might one put this code? Is ^ ctrl and % alt?

  4. #4
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    Wherever one wants!

    Yes it is.
    ____________________________________________
    Nihil simul inventum est et perfectum

    Abusus non tollit usum

    Last night I dreamed of a small consolation enjoyed only by the blind: Nobody knows the trouble I've not seen!
    James Thurber

  5. #5
    VBAX Mentor
    Joined
    Oct 2007
    Posts
    372
    Location
    I tried putting this into both the workbook module and a regular module but hitting ctrl alt pgdn or up doesn't appear to do anything.

  6. #6
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    The procedure Test just primes those keys so you have to run that procedure.
    ____________________________________________
    Nihil simul inventum est et perfectum

    Abusus non tollit usum

    Last night I dreamed of a small consolation enjoyed only by the blind: Nobody knows the trouble I've not seen!
    James Thurber

  7. #7
    VBAX Mentor
    Joined
    Oct 2007
    Posts
    372
    Location
    ah, Is there no way to enable it without running the procedure? I'm just wondering if there's a way to make it easier for the users w/out having them alt+f8 everytime they open the file.

  8. #8
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    Change the application configuration without running any code? Now that is an interesting concept ...

    Put it in the Workbook_Open event.
    ____________________________________________
    Nihil simul inventum est et perfectum

    Abusus non tollit usum

    Last night I dreamed of a small consolation enjoyed only by the blind: Nobody knows the trouble I've not seen!
    James Thurber

  9. #9
    VBAX Mentor
    Joined
    Oct 2007
    Posts
    372
    Location
    duh is probably appropriate.

  10. #10
    VBAX Mentor
    Joined
    Oct 2007
    Posts
    372
    Location
    How would I come up with the subscript for the current sheet?

    like if I wanted to switch between current and end instead of end and first then back? Where I would just temporarily store the current sheet# as a variable?

  11. #11
    VBAX Mentor
    Joined
    Oct 2007
    Posts
    372
    Location
    Something like this only that works.
    [VBA]Private Sub Workbook_Open()

    Application.OnKey "^%{PGUP}", "FirstSheet" 'Ctrl-Alt-PageUp
    Application.OnKey "^%{PGDN}", "LastSheet" 'Ctrl-Alt-PageDown
    End Sub


    Sub FirstSheet()

    ActiveWorkbook.csheet.Select
    End Sub

    Sub LastSheet()
    Dim csheet As Worksheet
    csheet = ActiveWorkSheet
    ActiveWorkbook.Worksheets(ActiveWorkbook.Worksheets.count).Select
    End Sub
    [/VBA]

Posting Permissions

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