Run Macro using WITH

ItalianPlatinum

Well-known Member
Joined
Mar 23, 2017
Messages
843
Office Version
  1. 365
  2. 2019
Platform
  1. Windows
Is there a way for me to run a macro designed for a particular sheet using WITH? My current approach seems inefficient. I don't think it causes me time drag but I am trying to optimize anywhere I can. Do I really need to activate the sheet in order to run the macro designed for that sheet?

VBA Code:
'clear and set filters
With WsSec
    .Range("H2:J6").Cells.ClearContents
    .Range("8:8").Cells.ClearContents
    .Range("ACCT") = F
    .Range("V") = V
    .Range("DATE") = RUN
    .Range("1ITEM") = "G"
    .Range("1OP") = "="
    .Range("1VALUE") = "S"
    .Range("A8:D8") = Array("D", "4", "A", "U")
    .Activate
    .Range("A10").CurrentRegion.Delete
End With

'clear and run
Call Sec2
 

Excel Facts

Can you AutoAverage in Excel?
There is a drop-down next to the AutoSum symbol. Open the drop-down to choose AVERAGE, COUNT, MAX, or MIN
If you avoid using 'Select' and 'Selection' and qualify your range references you often do not need to activate sheet. As with all things programming, the devil is in the details.
 
Upvote 0
The sec2 is very specific to that sheet though (WsSec). So if i remove activate as it is. it wouldn't operate unless on that sheet.
 
Upvote 0
If you say so. But it is absolutely possible to write code that does not require a given sheet to be active.
 
Upvote 0
That code isn't mine. It's a program from our vendor. I can though modify items in that workbook just not that code unfortunately. So that is part of my obstacle. So I activate the sheet then run that code. I am assuming there is no other way for me to not activate like I am doing then?
 
Upvote 0

Forum statistics

Threads
1,223,227
Messages
6,170,853
Members
452,361
Latest member
d3ad3y3

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