Macro throwing error when run from customized ribbon

0 votes

To sort the data, I have two identical macros. The only distinction is in the sort order of the columns. When executed manually, both macros function properly, but when launched from a custom button, SortByDate returns an error. SortByPPR operates as intended. There are no noticeable setup variations.

Cannot execute the macro is the message.

It's possible that this workbook's macro won't work or that all macros are disabled.

Sub SortByDate()
'
' SortByDate Macro
'

'
   Range("A6:O35").Select
    ActiveWorkbook.ActiveSheet.Sort.SortFields.Clear
   ActiveWorkbook.ActiveSheet.Sort.SortFields.Add2 Key:=Range("F6:F35") _
        , SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:=xlSortNormal
    With ActiveWorkbook.ActiveSheet.Sort
        .SetRange Range("A6:O35")
        .Header = xlNo
        .MatchCase = False
        .Orientation = xlTopToBottom
        .SortMethod = xlPinYin
        .Apply
    End With
End Sub

Sub SortByPPR()
'
' SortByPPR Macro
'
Range("A6:O35").Select
    ActiveWorkbook.ActiveSheet.Sort.SortFields.Clear
   ActiveWorkbook.ActiveSheet.Sort.SortFields.Add2 Key:=Range("b6:b35") _
        , SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:=xlSortNormal
    With ActiveWorkbook.ActiveSheet.Sort
        .SetRange Range("A6:O35")
        .Header = xlNo
        .MatchCase = False
        .Orientation = xlTopToBottom
        .SortMethod = xlPinYin
        .Apply
    End With
'
End Sub
Mar 31, 2023 in Others by narikkadan
• 63,420 points
350 views

1 answer to this question.

0 votes
The original macro was created in an XLSX file and afterwards converted to an XLSM file. The incorrect one continued to make reference to the xlsx file. The macro was deleted, and a new one was started in an XLSM, and it functions.
answered Mar 31, 2023 by Kithuzzz
• 38,010 points

Related Questions In Others

0 votes
1 answer

Excel to Word Macro resulting in Run-time error 462

Are you attempting this (UNTESTED)? I've commented ...READ MORE

answered Jan 29, 2023 in Others by narikkadan
• 63,420 points
670 views
+1 vote
0 answers

run ansible-playbook from jenkins on windows

I installed jenkins on windows machine.  Ansible ...READ MORE

Nov 4, 2019 in Others by Sivakumar
• 130 points
2,711 views
0 votes
1 answer

I am trying to run following command But I end up with an error :

Hii Nishant, You are running this command inside ...READ MORE

answered Apr 6, 2020 in Others by Niroj
• 82,880 points
1,594 views
0 votes
1 answer

ERROR: You need elevated Administrator privileges in order to run this script.

Hi@akhtar, I guess you are trying to run ...READ MORE

answered Sep 8, 2020 in Others by MD
• 95,440 points
1,682 views
0 votes
1 answer

Retrieve epay.info Balance with VBA and Excel

This code should log you in, provided ...READ MORE

answered Sep 5, 2018 in Blockchain by digger
• 26,740 points
917 views
0 votes
1 answer

ImportError: openpyxl is required for loading excel format files

Forget the PsychoPy complications for the time ...READ MORE

answered Oct 3, 2018 in Python by Priyaj
• 58,090 points
836 views
0 votes
1 answer

In Blue Prism how to split excel column data into TWO columns

This is how I am doing it. Dim ...READ MORE

answered Oct 15, 2018 in RPA by Priyaj
• 58,090 points
4,102 views
0 votes
1 answer

Excel Power Query: Using List.MatchAny on a column value

try this. let TableA = ...READ MORE

answered Oct 22, 2018 in Power BI by Annie97
• 2,160 points
3,854 views
0 votes
1 answer

Run macro when on Worksheet change (i.e. changing sheets, not data within sheet)

Try this: 'put this sub in ThisWorkbook module ...READ MORE

answered Mar 31, 2023 in Others by Kithuzzz
• 38,010 points
379 views
0 votes
1 answer

How to run Macro when press enter automatically and paste in different cell

A Worksheet Change: Keep Record of Each ...READ MORE

answered Apr 10, 2023 in Others by Kithuzzz
• 38,010 points
487 views
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP