code to run macro on selected sheet

FMW

New Member
Joined
Apr 10, 2020
Messages
12
Office Version
  1. 365
Platform
  1. Windows
Hello,
Everyday I received daily sales with a an excel sheet of anywhere from 10 to >100 job numbers. 1x per week I enter the necessary informtion into our invoicing program.
One of the steps I have to do first is sort each sheet by job number, customer, material. Then I also group customers (subtotal function).

I have macro for sorting and subtotal function. However, I cannot figure out code to run the macro on selected sheet. Currently, for example, my macro is:
 
How about this ? Or you can adjust accordingly

VBA Code:
Sub SortSalesDetail()

' SortSalesDetail Macro
' Sort Sales Detail
Dim ws As Worksheet

For Each ws In ActiveWorkbook.Worksheets
    If ws.Name Like "####-##-##_Tickets" Then
        ws.[A1].CurrentRegion.Sort key1:=ws.[E1], Header:=xlYes, Key2:=ws.[H1], Header:=xlYes
    End If
Next

End Sub
 
Upvote 0

Excel Facts

Add Bullets to Range
Select range. Press Ctrl+1. On Number tab, choose Custom. Type Alt+7 then space then @ sign (using 7 on numeric keypad)
perhaps change the sheet name, add an "S" to the name?

If this option works for you, you can add the below line before the End If line in the code in post # 11 & the macro will change the name once the sorting is completed so it doesn't get altered again by the macro

VBA Code:
ws.Name = ws.Name & "_s"
 
Upvote 0
I like that. I'll mark an identififer as "entered", which also alerts me to the fact that I've invoiced.
 
Upvote 0
I'm going with your adding the VBA code....."_s"
 
Upvote 0
THANK YOU! It's working great. Appreciate you taking time on Sunday night to answer. My next attempt: macro to perform subtotal!
Wish me luck.
Good night and stay safe always.
 
Upvote 0

Forum statistics

Threads
1,214,833
Messages
6,121,862
Members
449,052
Latest member
Fuddy_Duddy

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