run macro on specific worksheet upon closing

toddc

New Member
Joined
May 24, 2018
Messages
2
Hi all,

i have a workbook containing 2 worksheets. One is called "Transmittal" and the other is called "SAP". The transmittal worksheet is basically a template form that employees use to enter debits and credits. The SAP worksheet is basically a summary or a simple list of the same debits and credit entered in the transmittal worksheet but with some formatting done to them. I want to apply a certain code to be run only on the SAP worksheet upon closing the doc and saving it. I think i got the code right but it applies the formatting to the Transmittal worksheet not the SAP one. please help!

Private Sub Workbook_BeforeClose(Cancel As Boolean)
Range("A1:R49").AdvancedFilter Action:=xlFilterInPlace, CriteriaRange:= _
Sheets("Transmittal").Range("A100:A101"), Unique:=True


End Sub
 

Excel Facts

Using Function Arguments with nested formulas
If writing INDEX in Func. Arguments, type MATCH(. Use the mouse to click inside MATCH in the formula bar. Dialog switches to MATCH.
Hi all,

i have a workbook containing 2 worksheets. One is called "Transmittal" and the other is called "SAP". The transmittal worksheet is basically a template form that employees use to enter debits and credits. The SAP worksheet is basically a summary or a simple list of the same debits and credit entered in the transmittal worksheet but with some formatting done to them. I want to apply a certain code to be run only on the SAP worksheet upon closing the doc and saving it. I think i got the code right but it applies the formatting to the Transmittal worksheet not the SAP one. please help!

Private Sub Workbook_BeforeClose(Cancel As Boolean)
Range("A1:R49").AdvancedFilter Action:=xlFilterInPlace, CriteriaRange:= _
Sheets("Transmittal").Range("A100:A101"), Unique:=True


End Sub

Sheets("SAP").Range("A1:R49").AdvancedFilter Action:=xlFilterInPlace, CriteriaRange:= _
Sheets("Transmittal").Range("A100:A101"), Unique:=True
 
Last edited:
Upvote 0

Forum statistics

Threads
1,226,730
Messages
6,192,699
Members
453,747
Latest member
tylerhyatt04

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