Consulting

Results 1 to 5 of 5

Thread: Sheet selection + Shortcuts

  1. #1
    VBAX Regular
    Joined
    Apr 2007
    Posts
    8
    Location

    Sheet selection + Shortcuts

    Hi,

    I have a workbook with 10 sheets in it.
    2 of those sheets are ALL & STOCK RATINGS.
    I need to switch between these 2 sheets very often.
    I know excel works with the numbers linked to these names.
    Is there a script available, so I can use a shortcut.
    Let's say using ctrl + first letter of the sheet, or function keys,...

    Thx.

  2. #2
    VBAX Master
    Joined
    Jul 2006
    Location
    Belgium
    Posts
    1,286
    Location
    You could use the onkey event to change the behavior of a key. F1 for All and F2 for Stock Ratings. In workbook_open event use[vba]application.onkey "{F1}", "GoAll"
    application.onkey "{F2}", "GoStock"[/vba]In Workbook_beforeclose use[vba]application.onkey "{F1}"
    application.onkey "{F2}"[/vba]And in a normal module[vba]Sub GoAll()
    worksheets("All").Select
    End Sub
    Sub GoStock()
    worksheets("Stock Ratings").select
    End Sub[/vba]Or you could use one key F1 to switch between worksheets. One press selects the other based on the active sheet name.
    [vba]Sub Switch()
    if activesheet.name = "All" then
    worksheets("Stock Ratings").select
    else
    worksheets("All").select
    end if
    End Sub[/vba]

    Charlize

  3. #3
    VBAX Regular
    Joined
    Apr 2007
    Posts
    8
    Location
    I'm sure I'm doing something wrong, coz none works for me.
    I've tried then all, and after 1/2h I give up

  4. #4
    Administrator
    VP-Knowledge Base
    VBAX Grand Master mdmackillop's Avatar
    Joined
    May 2004
    Location
    Scotland
    Posts
    14,489
    Location
    Here's Charlize's code in a sample.
    F1 for All
    F2 for Stock Rating
    F3 to toggle between these two
    MVP (Excel 2008-2010)

    Post a workbook with sample data and layout if you want a quicker solution.


    To help indent your macros try Smart Indent

    Please remember to mark threads 'Solved'

  5. #5
    VBAX Regular
    Joined
    Apr 2007
    Posts
    8
    Location
    Thank You mdmackillop.
    You've been a great help, as always

Posting Permissions

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