Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 4
Default Array Function help

I want three sheets to autofit certain columns. Here is the code that I
currently have in my script... ugly.

Worksheets("Sheet1").Columns("A:Z").AutoFit
Worksheets("Sheet2").Columns("A:Z").AutoFit
Worksheets("Sheet3").Columns("A:Z").AutoFit

I want to try something more like:

Worksheets(Array("Sheet1","Sheet2","sheet3")).Colu mns("A:Z").AutoFit

I'm getting an error on this code, though. Thanks in advance for
helping a beginner.

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default Array Function help

Generally excel doesn't support grouped sheets which is what you are trying
to do.

for i = 1 to 3: worksheets("Sheet" & i).Columns("A:Z").Autofit: next
--
Regrds,
Tom Ogilvy

"DanQAEngineer" wrote in message
oups.com...
I want three sheets to autofit certain columns. Here is the code that I
currently have in my script... ugly.

Worksheets("Sheet1").Columns("A:Z").AutoFit
Worksheets("Sheet2").Columns("A:Z").AutoFit
Worksheets("Sheet3").Columns("A:Z").AutoFit

I want to try something more like:

Worksheets(Array("Sheet1","Sheet2","sheet3")).Colu mns("A:Z").AutoFit

I'm getting an error on this code, though. Thanks in advance for
helping a beginner.



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 691
Default Array Function help

Hi Dan,
Tom answered your question for the specific sheets, but when I
read Tom's answer I was thinking it referred to grouped sheets.
Anyway it might be well to include information for grouped sheets
as well. Of course it won't make the code any more beautiful, but it
may help make things more generic for similar questions.

To loop through the grouped sheets. See the additional
coding for looping through selectedsheets by Gary L. Brown within
the insert row macro
Insert a Row using a Macro to maintain formulas
http://www.mvps.org/dmcritchie/excel/insrtrow.htm

---
HTH,
David McRitchie, Microsoft MVP - Excel [site changed Nov. 2001]
My Excel Pages: http://www.mvps.org/dmcritchie/excel/excel.htm
Search Page: http://www.mvps.org/dmcritchie/excel/search.htm

"Tom Ogilvy" wrote in message ...
Generally excel doesn't support grouped sheets which is what you are trying
to do.

for i = 1 to 3: worksheets("Sheet" & i).Columns("A:Z").Autofit: next
--
Regrds,
Tom Ogilvy

"DanQAEngineer" wrote in message
oups.com...
I want three sheets to autofit certain columns. Here is the code that I
currently have in my script... ugly.

Worksheets("Sheet1").Columns("A:Z").AutoFit
Worksheets("Sheet2").Columns("A:Z").AutoFit
Worksheets("Sheet3").Columns("A:Z").AutoFit

I want to try something more like:

Worksheets(Array("Sheet1","Sheet2","sheet3")).Colu mns("A:Z").AutoFit

I'm getting an error on this code, though. Thanks in advance for
helping a beginner.





  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default Array Function help

My answer did refer to grouped sheets.

but there really is no reason to group them

v = Array("Sheet1", "Sheet5", "Sheet8")
worksheets(v).Select
for each sh in activeWindow.Selectedsheets

Next

just adds code. Just go straight to
v = Array("Sheet1", "Sheet5", "Sheet8")
for i = lbound(v) to ubound(v)
set sh = worksheets(v(i))

Next

--
Regards,
Tom Ogilvy


"David McRitchie" wrote in message
...
Hi Dan,
Tom answered your question for the specific sheets, but when I
read Tom's answer I was thinking it referred to grouped sheets.
Anyway it might be well to include information for grouped sheets
as well. Of course it won't make the code any more beautiful, but it
may help make things more generic for similar questions.

To loop through the grouped sheets. See the additional
coding for looping through selectedsheets by Gary L. Brown within
the insert row macro
Insert a Row using a Macro to maintain formulas
http://www.mvps.org/dmcritchie/excel/insrtrow.htm

---
HTH,
David McRitchie, Microsoft MVP - Excel [site changed Nov. 2001]
My Excel Pages: http://www.mvps.org/dmcritchie/excel/excel.htm
Search Page: http://www.mvps.org/dmcritchie/excel/search.htm

"Tom Ogilvy" wrote in message

...
Generally excel doesn't support grouped sheets which is what you are

trying
to do.

for i = 1 to 3: worksheets("Sheet" & i).Columns("A:Z").Autofit: next
--
Regrds,
Tom Ogilvy

"DanQAEngineer" wrote in message
oups.com...
I want three sheets to autofit certain columns. Here is the code that

I
currently have in my script... ugly.

Worksheets("Sheet1").Columns("A:Z").AutoFit
Worksheets("Sheet2").Columns("A:Z").AutoFit
Worksheets("Sheet3").Columns("A:Z").AutoFit

I want to try something more like:

Worksheets(Array("Sheet1","Sheet2","sheet3")).Colu mns("A:Z").AutoFit

I'm getting an error on this code, though. Thanks in advance for
helping a beginner.







  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 691
Default Array Function help

I guess I always think of "grouped sheets" as being preselected
within Excel before invoking a macro. I certainly agree that
it would not be advantageous to group the sheets within a
macro just to be able to use code that handles grouped sheets.

I can't find the term "grouped sheets" in help even though "ungroup sheets" is the first menu item when you right click on group
sheets with the
Ctrl key. (Excel 2000)
---
HTH,
David McRitchie, Microsoft MVP - Excel [site changed Nov. 2001]
My Excel Pages: http://www.mvps.org/dmcritchie/excel/excel.htm
Search Page: http://www.mvps.org/dmcritchie/excel/search.htm

"Tom Ogilvy" wrote in message ...
My answer did refer to grouped sheets.

but there really is no reason to group them

v = Array("Sheet1", "Sheet5", "Sheet8")
worksheets(v).Select
for each sh in activeWindow.Selectedsheets

Next

just adds code. Just go straight to
v = Array("Sheet1", "Sheet5", "Sheet8")
for i = lbound(v) to ubound(v)
set sh = worksheets(v(i))

Next

--
Regards,
Tom Ogilvy


"David McRitchie" wrote in message
...
Hi Dan,
Tom answered your question for the specific sheets, but when I
read Tom's answer I was thinking it referred to grouped sheets.
Anyway it might be well to include information for grouped sheets
as well. Of course it won't make the code any more beautiful, but it
may help make things more generic for similar questions.

To loop through the grouped sheets. See the additional
coding for looping through selectedsheets by Gary L. Brown within
the insert row macro
Insert a Row using a Macro to maintain formulas
http://www.mvps.org/dmcritchie/excel/insrtrow.htm

---
HTH,
David McRitchie, Microsoft MVP - Excel [site changed Nov. 2001]
My Excel Pages: http://www.mvps.org/dmcritchie/excel/excel.htm
Search Page: http://www.mvps.org/dmcritchie/excel/search.htm

"Tom Ogilvy" wrote in message

...
Generally excel doesn't support grouped sheets which is what you are

trying
to do.

for i = 1 to 3: worksheets("Sheet" & i).Columns("A:Z").Autofit: next
--
Regrds,
Tom Ogilvy

"DanQAEngineer" wrote in message
oups.com...
I want three sheets to autofit certain columns. Here is the code that

I
currently have in my script... ugly.

Worksheets("Sheet1").Columns("A:Z").AutoFit
Worksheets("Sheet2").Columns("A:Z").AutoFit
Worksheets("Sheet3").Columns("A:Z").AutoFit

I want to try something more like:

Worksheets(Array("Sheet1","Sheet2","sheet3")).Colu mns("A:Z").AutoFit

I'm getting an error on this code, though. Thanks in advance for
helping a beginner.











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
Array function - I think! CES Excel Worksheet Functions 8 March 30th 10 06:11 PM
OR function in array-entered IF function veggies27 Excel Worksheet Functions 8 March 11th 08 06:32 PM
Array Function John Michl Excel Worksheet Functions 6 March 20th 06 03:16 PM
#DIV/0! in the array function Sergun Excel Worksheet Functions 1 November 25th 05 01:14 PM
UDF Array function Dave Peterson[_3_] Excel Programming 0 July 10th 03 04:30 AM


All times are GMT +1. The time now is 07:50 AM.

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"