+ Reply to Thread
Results 1 to 4 of 4

Keyboard shortcut will not work

Hybrid View

  1. #1
    Registered User
    Join Date
    01-07-2008
    Posts
    65

    Keyboard shortcut will not work

    I'm having some trouble getting the code below to work with the keyboard shortcut. However, it works when I run it from the macro menu. I modified it from a macro written for me by royUK. I had the same problem with that macro and I "fixed" it by recording a macro, specifying my chosen keyboard shortcut, and hitting the stop record button before doing anything else. Then I pasted the rest of the code from royUK's maco. It worked perfectly. I did this exact same thing with the code I modified, and I'm still having the same problem. So, clearly, I don't understand what's going on. There must be some small syntax I'm unaware of that is causing otherwise fine macros not to link to their shortcuts.

    Can anyone help?

    I should also ad that I am less than a novice at writing macros. Last night was the first time I ever ever played with the code at all. I have virtually no idea what I'm doing.

    Sub day_4___SortByMust()
    '
    ' day_4___SortByMust Macro
    '
    ' Keyboard Shortcut: Ctrl+Shift+M
        ActiveCell.Offset(0, -22).Range("A1:X30").Select
        With ActiveSheet
            .Sort.SortFields.Clear
                    .Sort.SortFields.Add Key:=ActiveCell.Offset(0 _
                               , 19).Range("A1:A30"), SortOn:=xlSortOnValues, Order:=xlDescending, _
                                                        DataOption:=xlSortNormal
            .Sort.SortFields.Add Key:=ActiveCell.Offset(0 _
                               , 22).Range("A1:A30"), SortOn:=xlSortOnValues, Order:=xlAscending, _
                                                        DataOption:=xlSortNormal
            With .Sort
                .SetRange ActiveCell.Range("A1:X30")
                .Header = xlGuess
                .MatchCase = False
                .Orientation = xlTopToBottom
                .SortMethod = xlPinYin
                .Apply
            End With
        End With
    End Sub

  2. #2
    Forum Guru
    Join Date
    03-02-2006
    Location
    Los Angeles, Ca
    MS-Off Ver
    WinXP/MSO2007;Win10/MSO2016
    Posts
    12,663

    Re: Keyboard shortcut will not work

    What kind of trouble are you having, specifically?
    What column was the cursor in when you tried to run the macro?
    You have a line,
    ActiveCell.Offset(0, -22).Range("A1:X30").Select
    that tries to move 22 columns to the left of the active cell when the macro runs, If you are at some column to the left of 'V' then you are: off the sheet=crash macro. As it is, the rows and columns to sort depends on the location of the active cell, is that your intent?
    Last edited by protonLeah; 04-04-2010 at 03:14 AM.
    Ben Van Johnson

  3. #3
    Registered User
    Join Date
    01-07-2008
    Posts
    65

    Re: Keyboard shortcut will not work

    Yes, that is my intent. Basically I have a lot of information in plain rows and columns. In that configuration, I can easily manipulate it, but this specific macro works on the sheets that have pulled that information into "blocks." By selecting the cell in column AA at the top of a block and running the macro, I can sort that block.

    It actually works completely when I use the macro menu (if that's what it's called; whatever comes up when you hit Alt+F8). It's just that the keyboard shortcut does not cause the macro to run at all. And I have tried using different letters like A, X, and H, just in case the problem was being caused by some conflict with a preexisting shortcut. But I have had no luck so far.

  4. #4
    Forum Guru
    Join Date
    03-02-2006
    Location
    Los Angeles, Ca
    MS-Off Ver
    WinXP/MSO2007;Win10/MSO2016
    Posts
    12,663

    Re: Keyboard shortcut will not work

    I guess I don't understand. I copied your macro into a standard module (module1) and closed the VBE. Then , back on the worksheet, I chose the Macros Menu, highlighted the macro and under Options selected ctrl+shft+M as the shortcut keys. It runs ok, though the sheet was blank.
    Attached Files Attached Files

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

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