Home |
Search |
Today's Posts |
#1
Posted to microsoft.public.excel.worksheet.functions
|
|||
|
|||
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
Posted to microsoft.public.excel.worksheet.functions
|
|||
|
|||
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
Posted to microsoft.public.excel.worksheet.functions
|
|||
|
|||
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
Posted to microsoft.public.excel.worksheet.functions
|
|||
|
|||
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
Posted to microsoft.public.excel.worksheet.functions
|
|||
|
|||
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
Posted to microsoft.public.excel.worksheet.functions
|
|||
|
|||
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
Posted to microsoft.public.excel.worksheet.functions
|
|||
|
|||
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
Posted to microsoft.public.excel.worksheet.functions
|
|||
|
|||
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
Posted to microsoft.public.excel.worksheet.functions
|
|||
|
|||
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 |
Display Modes | |
|
|
Similar Threads | ||||
Thread | Forum | |||
how do I include multiple worksheets to a countif formula? | Excel Discussion (Misc queries) | |||
Pivot Table - include multiple worksheets with different ranges. | Excel Discussion (Misc queries) | |||
Formula needs to include several worksheet tabs in one workbook | Excel Discussion (Misc queries) | |||
include criteria to 'rank based array function' | Excel Discussion (Misc queries) | |||
How do i include the original workbook in the email message creat. | Excel Discussion (Misc queries) |