Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.worksheet.functions
external usenet poster
 
Posts: 72
Default How do I write an array to include all worksheets in a workbook?

I am trying to add to a marco to auto fit columns A through H in all
worksheets. How would I add this so it does not matter how many tabs are in
the workbook as it will continually change?
--
Thank you, Jodie
  #2   Report Post  
Posted to microsoft.public.excel.worksheet.functions
external usenet poster
 
Posts: 11,501
Default How do I write an array to include all worksheets in a workbook?

hi,

Right click any of your sheet tab, view code and paste this code in and run it

Sub sonic()
For x = 1 To Worksheets.Count
Sheets(x).Columns("A:H").AutoFit
Next
End Sub

Mike

"Jodie" wrote:

I am trying to add to a marco to auto fit columns A through H in all
worksheets. How would I add this so it does not matter how many tabs are in
the workbook as it will continually change?
--
Thank you, Jodie

  #3   Report Post  
Posted to microsoft.public.excel.worksheet.functions
external usenet poster
 
Posts: 563
Default How do I write an array to include all worksheets in a workbook?

Just out of interest, why did you suggest making this a sheet subroutine
rather than putting it in a general module?
best wsihes

--
Bernard Liengme
Microsoft Excel MVP
http://people.stfx.ca/bliengme

"Mike H" wrote in message
...
hi,

Right click any of your sheet tab, view code and paste this code in and
run it

Sub sonic()
For x = 1 To Worksheets.Count
Sheets(x).Columns("A:H").AutoFit
Next
End Sub

Mike

"Jodie" wrote:

I am trying to add to a marco to auto fit columns A through H in all
worksheets. How would I add this so it does not matter how many tabs are
in
the workbook as it will continually change?
--
Thank you, Jodie


  #4   Report Post  
Posted to microsoft.public.excel.worksheet.functions
external usenet poster
 
Posts: 11,501
Default How do I write an array to include all worksheets in a workboo

Bernard,

Several reasons:-

It will work

I guess (and apologise to the OP if i'm wrong) that the OP is very
inexperienced and entering worksheet code utilises less steps than entering a
general module. Three mouse mouse clicks and the code is in.

It's my habit and preferred way of doing it 'provided' I'm not reading from
or writing to sheets other than the one that contains the code. Although
there's no reason why worksheet code couldn't work too if doing that.

I'm aware of the convention that worksheet modules are for event code but
have never heard a compelling argument that it's anything other than that, 'a
convention'.

Mike



"Bernard Liengme" wrote:

Just out of interest, why did you suggest making this a sheet subroutine
rather than putting it in a general module?
best wsihes

--
Bernard Liengme
Microsoft Excel MVP
http://people.stfx.ca/bliengme

"Mike H" wrote in message
...
hi,

Right click any of your sheet tab, view code and paste this code in and
run it

Sub sonic()
For x = 1 To Worksheets.Count
Sheets(x).Columns("A:H").AutoFit
Next
End Sub

Mike

"Jodie" wrote:

I am trying to add to a marco to auto fit columns A through H in all
worksheets. How would I add this so it does not matter how many tabs are
in
the workbook as it will continually change?
--
Thank you, Jodie



  #5   Report Post  
Posted to microsoft.public.excel.worksheet.functions
external usenet poster
 
Posts: 806
Default How do I write an array to include all worksheets in a workboo



Several reasons:-

It will work


.... unless some innocent user deletes this special purpose sheet with
the implicit general functionality.

Why not just say 1. Press ALT + F11 2. Insert a new module 3. Copy the
code into the new module 4. Go back to worksheet and use it?

Regards,
Bernd


  #6   Report Post  
Posted to microsoft.public.excel.worksheet.functions
external usenet poster
 
Posts: 11,501
Default How do I write an array to include all worksheets in a workboo

As stated

It's my habit and preferred way of doing it 'provided' I'm not reading from
or writing to sheets other than the one that contains the code. Although
there's no reason why worksheet code couldn't work too if doing that

If you believe this is fundamentally incorrect provide a compelling argument
as to why.

Before you reply consider why Microsoft provide a 'general' option in the
dropdown of worksheet modules if entering something other than event code is
inappropriate.

Mike

"Bernd P" wrote:



Several reasons:-

It will work


.... unless some innocent user deletes this special purpose sheet with
the implicit general functionality.

Why not just say 1. Press ALT + F11 2. Insert a new module 3. Copy the
code into the new module 4. Go back to worksheet and use it?

Regards,
Bernd

  #7   Report Post  
Posted to microsoft.public.excel.worksheet.functions
external usenet poster
 
Posts: 8,520
Default How do I write an array to include all worksheets in a workboo

If you believe this is fundamentally incorrect provide a compelling argument
as to why.
Before you reply consider why Microsoft provide a 'general' option in the
dropdown of worksheet modules if entering something other than event code is
inappropriate.


Will just give it a try..

---Private functions/procedures which are to be called from the sheet events
and are only applicable to that particular sheet are usually placed in that
module itself. (can either be a worksheet or a chart) so that if the sheet is
copied/moved to another workbook these functions/procedures would
automatically be saved along with the sheet. For example from the sheet
events if you need to do repeated tasks; like the below which are only
applicable for that particular sheet; these are ideally placed in the sheet
module.

--- It is generally accepted as good programming practice that only
procedures/functions which are used only within that module be placed in that
and others be placed in the general module. (Like placing a worksheet change
event for a ***particular*** sheet in the 'This Workbook'). In the OP's case
since the macro works on all the worksheets of the workbook it would be
considered in-appropriate to place this in sheet module..

If this post helps click Yes
---------------
Jacob Skaria


"Mike H" wrote:

As stated

It's my habit and preferred way of doing it 'provided' I'm not reading from
or writing to sheets other than the one that contains the code. Although
there's no reason why worksheet code couldn't work too if doing that

If you believe this is fundamentally incorrect provide a compelling argument
as to why.

Before you reply consider why Microsoft provide a 'general' option in the
dropdown of worksheet modules if entering something other than event code is
inappropriate.

Mike

"Bernd P" wrote:



Several reasons:-

It will work


.... unless some innocent user deletes this special purpose sheet with
the implicit general functionality.

Why not just say 1. Press ALT + F11 2. Insert a new module 3. Copy the
code into the new module 4. Go back to worksheet and use it?

Regards,
Bernd

  #8   Report Post  
Posted to microsoft.public.excel.worksheet.functions
external usenet poster
 
Posts: 8,520
Default How do I write an array to include all worksheets in a workboo

Mike; I re-read what I posted and the below two sentences found to be
confusing ...

For example from the sheet events if you need to do repeated tasks; like the below

I am not referring to the OPs requirement but way planning to copy few
samples of functions/procedures which are applicable only to that sheet;
later left that idea...Hope you can understand what would be those

(Like placing a worksheet change event for a ***particular*** sheet in the 'This Workbook').

should have also added that doing the above would not be considered as not a
good practice.

If this post helps click Yes
---------------
Jacob Skaria


"Jacob Skaria" wrote:

If you believe this is fundamentally incorrect provide a compelling argument
as to why.
Before you reply consider why Microsoft provide a 'general' option in the
dropdown of worksheet modules if entering something other than event code is
inappropriate.


Will just give it a try..

---Private functions/procedures which are to be called from the sheet events
and are only applicable to that particular sheet are usually placed in that
module itself. (can either be a worksheet or a chart) so that if the sheet is
copied/moved to another workbook these functions/procedures would
automatically be saved along with the sheet. For example from the sheet
events if you need to do repeated tasks; like the below which are only
applicable for that particular sheet; these are ideally placed in the sheet
module.

--- It is generally accepted as good programming practice that only
procedures/functions which are used only within that module be placed in that
and others be placed in the general module. (Like placing a worksheet change
event for a ***particular*** sheet in the 'This Workbook'). In the OP's case
since the macro works on all the worksheets of the workbook it would be
considered in-appropriate to place this in sheet module..

If this post helps click Yes
---------------
Jacob Skaria


"Mike H" wrote:

As stated

It's my habit and preferred way of doing it 'provided' I'm not reading from
or writing to sheets other than the one that contains the code. Although
there's no reason why worksheet code couldn't work too if doing that

If you believe this is fundamentally incorrect provide a compelling argument
as to why.

Before you reply consider why Microsoft provide a 'general' option in the
dropdown of worksheet modules if entering something other than event code is
inappropriate.

Mike

"Bernd P" wrote:



Several reasons:-

It will work


.... unless some innocent user deletes this special purpose sheet with
the implicit general functionality.

Why not just say 1. Press ALT + F11 2. Insert a new module 3. Copy the
code into the new module 4. Go back to worksheet and use it?

Regards,
Bernd

  #9   Report Post  
Posted to microsoft.public.excel.worksheet.functions
external usenet poster
 
Posts: 563
Default How do I write an array to include all worksheets in a workboo

Good to know
Bernard

"Mike H" wrote in message
...
Bernard,

Several reasons:-

It will work

I guess (and apologise to the OP if i'm wrong) that the OP is very
inexperienced and entering worksheet code utilises less steps than
entering a
general module. Three mouse mouse clicks and the code is in.

It's my habit and preferred way of doing it 'provided' I'm not reading
from
or writing to sheets other than the one that contains the code. Although
there's no reason why worksheet code couldn't work too if doing that.

I'm aware of the convention that worksheet modules are for event code but
have never heard a compelling argument that it's anything other than that,
'a
convention'.

Mike



"Bernard Liengme" wrote:

Just out of interest, why did you suggest making this a sheet subroutine
rather than putting it in a general module?
best wsihes

--
Bernard Liengme
Microsoft Excel MVP
http://people.stfx.ca/bliengme

"Mike H" wrote in message
...
hi,

Right click any of your sheet tab, view code and paste this code in and
run it

Sub sonic()
For x = 1 To Worksheets.Count
Sheets(x).Columns("A:H").AutoFit
Next
End Sub

Mike

"Jodie" wrote:

I am trying to add to a marco to auto fit columns A through H in all
worksheets. How would I add this so it does not matter how many tabs
are
in
the workbook as it will continually change?
--
Thank you, Jodie



Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
how do I include multiple worksheets to a countif formula? Brigette Excel Discussion (Misc queries) 1 August 19th 09 10:58 PM
Pivot Table - include multiple worksheets with different ranges. Tracy Excel Discussion (Misc queries) 1 December 13th 07 06:27 PM
Formula needs to include several worksheet tabs in one workbook klafert Excel Discussion (Misc queries) 12 July 2nd 07 02:16 PM
include criteria to 'rank based array function' TUNGANA KURMA RAJU Excel Discussion (Misc queries) 2 September 2nd 06 01:15 PM
How do i include the original workbook in the email message creat. ebxr8 Excel Discussion (Misc queries) 4 April 9th 05 12:25 AM


All times are GMT +1. The time now is 07:53 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"