Quick question about With, formatting and macro recording

Luke777

Board Regular
Joined
Aug 10, 2020
Messages
246
Office Version
  1. 365
Platform
  1. Windows
Hi all,

I've just recorded a macro on a fresh wb with only one sheet - its a long list of formatting things like fill colours, column widths, font size/colour.

I've noticed, however, that in the macro no sheet reference is recorded, only ranges, because there is only a single sheet. If I wish to specify that this macro should run on a specific sheet or bring it over to another wb at some point in the future, would i be best to sandwich the entire recorded marco with "With Worksheets("name") bla bla bla End With"?

Also I know recording macros this way ends up generating a much longer macro than strictly necessary but I'm not spending too much time faffing about with formatting shenanigans :)

Thanks all!
 

Excel Facts

What is the fastest way to copy a formula?
If A2:A50000 contain data. Enter a formula in B2. Select B2. Double-click the Fill Handle and Excel will shoot the formula down to B50000.
That is one way.

Or, you could just select/activate the sheet you want to run it against at the beginning of the code, as without any sheet references, it defaults to run against whatever the active sheet is at the time.
 
Upvote 0

Forum statistics

Threads
1,214,899
Messages
6,122,155
Members
449,068
Latest member
shiz11713

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