Macro works when I go to developer ribbon and push it but I have to go to each worksheet I want to assign and press the run button

Hikari

New Member
Joined
Feb 6, 2022
Messages
1
Office Version
  1. 365
Platform
  1. Windows
Public Sub Organize()

On Error Resume Next
ThisWorkbook.Worksheets("Expense").Sort.SortFields.Clear
ThisWorkbook.Worksheets("Income").Sort.SortFields.Clear
ThisWorkbook.Worksheets("Summary").Sort.SortFields.Clear

ThisWorkbook.Worksheets("Expense").Range("ExpenseData").Sort Key1:=Range("A2"), Key2:=Range("B2"), Key3:=Range("C2"), Order1:=xlAscending, Order2:=xlAscending, Order3:=xlAscending
ThisWorkbook.Worksheets("Income").Range("IncomeData").Sort Key1:=Range("A2"), Key2:=Range("B2"), Key3:=Range("C2"), Order1:=xlAscending, Order2:=xlAscending, Order3:=xlAscending
ThisWorkbook.Worksheets("Summary").Range("SummaryData").Sort Key1:=Range("A2"), Key2:=Range("C2"), Order1:=xlAscending, Order2:=xlAscending

On Error GoTo 0


End Sub

This is my code and I want it to run on every page simultaneously when I hit the button that has assigned macro. Currently I have to go to each sheets to make this macro work. I would love to receive some advices.
 

Excel Facts

Ambidextrous Undo
Undo last command with Ctrl+Z or Alt+Backspace. If you use the Undo icon in the QAT, open the drop-down arrow to undo up to 100 steps.
put the macro in the PERSONAL workbook. Then it can run on ANY sheet.

record a macro,
change STORE MACRO IN: personal
click a cell.
save
now move the module to the personal project workbook.
 
Upvote 0
Can you see if this makes a difference:
VBA Code:
Public Sub Organize()

    On Error Resume Next
    
    With ThisWorkbook.Worksheets("Expense")
        .Sort.SortFields.Clear
        .Range("ExpenseData").Sort Key1:=.Range("A2"), Key2:=.Range("B2"), Key3:=.Range("C2"), Order1:=xlAscending, Order2:=xlAscending, Order3:=xlAscending
    End With
    
    With ThisWorkbook.Worksheets("Income")
        .Sort.SortFields.Clear
        .Range("IncomeData").Sort Key1:=.Range("A2"), Key2:=.Range("B2"), Key3:=.Range("C2"), Order1:=xlAscending, Order2:=xlAscending, Order3:=xlAscending
    End With
    
    With ThisWorkbook.Worksheets("Summary")
        .Sort.SortFields.Clear
        .Range("SummaryData").Sort Key1:=.Range("A2"), Key2:=.Range("C2"), Order1:=xlAscending, Order2:=xlAscending
    End With
    
    On Error GoTo 0


End Sub
 
Upvote 0
Solution

Forum statistics

Threads
1,214,918
Messages
6,122,257
Members
449,075
Latest member
staticfluids

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top