Why does my Excel macro fail when run from a hotkey and work when run from the macros ribbon?

0

I am really confused by what is going on with a macro I created to parse out space delimited files.

The macro runs successfully as long as I select the macros ribbon and the macro from the dialog box.

If I try to run it using a hotkey however, all that occurs is column A is highlighted then column B is highlighted, then it jumps back to highlighting column A.

I have tried several different hotkey combinations the current is Ctrl+Shift+Y.

The following is the macros code and any help would be appreciated.

Sub DLEligibleParse()
    '
    ' DLeligibleparse Macro
    ' this utilizes the eligible list end positionseff 4-22-12
    '
    '
    Columns("B:B").Select
    Selection.NumberFormat = "0000000000000"
    Columns("A:A").Select
    Selection.TextToColumns Destination:=Range("A1"), DataType:=xlFixedWidth, _
        FieldInfo:=Array(Array(0, 1), Array(13, 1), Array(43, 1), Array(45, 1), Array(80, 1), _
        Array(115, 1), Array(150, 1), Array(185, 1), Array(220, 1), Array(222, 1), Array(231, 1), _
        Array(266, 1), Array(301, 1), Array(336, 1), Array(371, 1), Array(373, 1), Array(382, 1), _
        Array(385, 1), Array(402, 1), Array(455, 1), Array(490, 1), Array(525, 1), Array(527, 1), _
        Array(536, 1), Array(539, 1), Array(549, 1), Array(559, 1), Array(564, 1), Array(579, 1), _
        Array(581, 1), Array(596, 1), Array(598, 1), Array(610, 1), Array(622, 1), Array(640, 1), _
        Array(655, 1), Array(670, 1), Array(687, 1), Array(702, 1), Array(717, 1), Array(734, 1), _
        Array(749, 1), Array(764, 1), Array(781, 1), Array(796, 1), Array(811, 1), Array(828, 1), _
        Array(843, 1), Array(858, 1), Array(875, 1), Array(890, 1), Array(905, 1), Array(922, 1), _
        Array(937, 1), Array(952, 1), Array(969, 1), Array(984, 1), Array(999, 1), Array(1016, 1), _
        Array(1031, 1), Array(1046, 1), Array(1063, 1), Array(1078, 1), Array(1093, 1), Array( _
        1110, 1), Array(1125, 1), Array(1140, 1), Array(1157, 1), Array(1172, 1), Array(1187, 1), _
        Array(1204, 1), Array(1212, 1), Array(1224, 1), Array(1225, 1), Array(1226, 1), Array( _
        1227, 1), Array(1228, 1)), TrailingMinusNumbers:=True
    Cells.Select
    Cells.EntireColumn.AutoFit
    Range("A1").Select
End Sub

small3687

Posted 2013-05-15T20:37:24.680

Reputation: 55

If the macro works when you run it from the Macro Menu then it is not an issue with the code. Check the shortcut again. Shift would only be used if you held it (capital Y) when you set the shortcut. Above you indicated a lowercase y. Also, make sure there isn't another macro with the same shortcut. – CharlieRB – 2013-05-16T19:40:07.233

I made sure that there are no macros with the same shortcut and I noticed that when using a ctrl+shift letter combination the letters will always be capitalized. It is a rather confounding issue. – small3687 – 2013-06-06T23:19:18.657

Answers

0

I would reccomend getting rid of the "select" statements. They mess up code execution in unpredictable ways. Try this.

Sub DLEligibleParse()
    '
    ' DLeligibleparse Macro
    ' this utilizes the eligible list end positionseff 4-22-12
    '
    '
    Columns("B:B").NumberFormat = "0000000000000"
    Columns("A:A").TextToColumns Destination:=Range("A1"), DataType:=xlFixedWidth, _
        FieldInfo:=Array(Array(0, 1), Array(13, 1), Array(43, 1), Array(45, 1), Array(80, 1), _
        Array(115, 1), Array(150, 1), Array(185, 1), Array(220, 1), Array(222, 1), Array(231, 1), _
        Array(266, 1), Array(301, 1), Array(336, 1), Array(371, 1), Array(373, 1), Array(382, 1), _
        Array(385, 1), Array(402, 1), Array(455, 1), Array(490, 1), Array(525, 1), Array(527, 1), _
        Array(536, 1), Array(539, 1), Array(549, 1), Array(559, 1), Array(564, 1), Array(579, 1), _
        Array(581, 1), Array(596, 1), Array(598, 1), Array(610, 1), Array(622, 1), Array(640, 1), _
        Array(655, 1), Array(670, 1), Array(687, 1), Array(702, 1), Array(717, 1), Array(734, 1), _
        Array(749, 1), Array(764, 1), Array(781, 1), Array(796, 1), Array(811, 1), Array(828, 1), _
        Array(843, 1), Array(858, 1), Array(875, 1), Array(890, 1), Array(905, 1), Array(922, 1), _
        Array(937, 1), Array(952, 1), Array(969, 1), Array(984, 1), Array(999, 1), Array(1016, 1), _
        Array(1031, 1), Array(1046, 1), Array(1063, 1), Array(1078, 1), Array(1093, 1), Array( _
        1110, 1), Array(1125, 1), Array(1140, 1), Array(1157, 1), Array(1172, 1), Array(1187, 1), _
        Array(1204, 1), Array(1212, 1), Array(1224, 1), Array(1225, 1), Array(1226, 1), Array( _
        1227, 1), Array(1228, 1)), TrailingMinusNumbers:=True
    Cells.EntireColumn.AutoFit
End Sub

Sagar

Posted 2013-05-15T20:37:24.680

Reputation: 54