Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 29
Default select sheets

I have the following code:

Sheets(Array("Bridal", "Executive", "Facilities", "Finance",
"Furniture", "Housewares", _
"Human Resources", "Human Resources", "MIO", "Planning", "Real
Estate", "Retail Technology", _
"Stores Merch", "Tabletop", "Textiles", "Visual")).Select

How can I simplify this so that I select the third sheet in the file to
the last sheet in the file?

THanks

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,758
Default select sheets

I'd do something like:

Option Explicit
Sub testme()
Dim iCtr As Long
Dim myLimit As Long

myLimit = 2
If Sheets.Count myLimit Then
For iCtr = myLimit To Sheets.Count
Sheets(iCtr).Select Replace:=CBool(iCtr = (myLimit + 1))
Next iCtr
End If
End Sub



snax500 wrote:

I have the following code:

Sheets(Array("Bridal", "Executive", "Facilities", "Finance",
"Furniture", "Housewares", _
"Human Resources", "Human Resources", "MIO", "Planning", "Real
Estate", "Retail Technology", _
"Stores Merch", "Tabletop", "Textiles", "Visual")).Select

How can I simplify this so that I select the third sheet in the file to
the last sheet in the file?

THanks


--

Dave Peterson
  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 121
Default select sheets

Dave, I had to study what you were doing at first, but the portion beginning
"Replace..." of this line

Sheets(iCtr).Select Replace:=CBool(iCtr = (myLimit + 1))

was a work of art!

Bill
"Dave Peterson" wrote in message
...
I'd do something like:

Option Explicit
Sub testme()
Dim iCtr As Long
Dim myLimit As Long

myLimit = 2
If Sheets.Count myLimit Then
For iCtr = myLimit To Sheets.Count
Sheets(iCtr).Select Replace:=CBool(iCtr = (myLimit + 1))
Next iCtr
End If
End Sub



snax500 wrote:

I have the following code:

Sheets(Array("Bridal", "Executive", "Facilities", "Finance",
"Furniture", "Housewares", _
"Human Resources", "Human Resources", "MIO", "Planning", "Real
Estate", "Retail Technology", _
"Stores Merch", "Tabletop", "Textiles", "Visual")).Select

How can I simplify this so that I select the third sheet in the file to
the last sheet in the file?

THanks


--

Dave Peterson



  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,758
Default select sheets

It is very nice. I forgot who I stole, er, borrowed it from!

William Benson wrote:

Dave, I had to study what you were doing at first, but the portion beginning
"Replace..." of this line

Sheets(iCtr).Select Replace:=CBool(iCtr = (myLimit + 1))

was a work of art!

Bill
"Dave Peterson" wrote in message
...
I'd do something like:

Option Explicit
Sub testme()
Dim iCtr As Long
Dim myLimit As Long

myLimit = 2
If Sheets.Count myLimit Then
For iCtr = myLimit To Sheets.Count
Sheets(iCtr).Select Replace:=CBool(iCtr = (myLimit + 1))
Next iCtr
End If
End Sub



snax500 wrote:

I have the following code:

Sheets(Array("Bridal", "Executive", "Facilities", "Finance",
"Furniture", "Housewares", _
"Human Resources", "Human Resources", "MIO", "Planning", "Real
Estate", "Retail Technology", _
"Stores Merch", "Tabletop", "Textiles", "Visual")).Select

How can I simplify this so that I select the third sheet in the file to
the last sheet in the file?

THanks


--

Dave Peterson


--

Dave Peterson
  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default select sheets

Jake Marx was the first person I saw use it, but wouldn't doubt that J.E.
McGimsey would have used something like that. He likes to pack as much
action as possible in a line of code.

--
Regards,
Tom Ogilvy


"Dave Peterson" wrote in message
...
It is very nice. I forgot who I stole, er, borrowed it from!

William Benson wrote:

Dave, I had to study what you were doing at first, but the portion

beginning
"Replace..." of this line

Sheets(iCtr).Select Replace:=CBool(iCtr = (myLimit + 1))

was a work of art!

Bill
"Dave Peterson" wrote in message
...
I'd do something like:

Option Explicit
Sub testme()
Dim iCtr As Long
Dim myLimit As Long

myLimit = 2
If Sheets.Count myLimit Then
For iCtr = myLimit To Sheets.Count
Sheets(iCtr).Select Replace:=CBool(iCtr = (myLimit + 1))
Next iCtr
End If
End Sub



snax500 wrote:

I have the following code:

Sheets(Array("Bridal", "Executive", "Facilities", "Finance",
"Furniture", "Housewares", _
"Human Resources", "Human Resources", "MIO", "Planning", "Real
Estate", "Retail Technology", _
"Stores Merch", "Tabletop", "Textiles", "Visual")).Select

How can I simplify this so that I select the third sheet in the file

to
the last sheet in the file?

THanks

--

Dave Peterson


--

Dave Peterson





  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 29
Default select sheets

It really is. I wrote to Dave for an explanation. Here it is...



Take a look at help for .select.

It has an option to replace the selected sheet or keep adding.

False means that it's just "added" to the current group of selected
sheets.

True means to select that sheet and "unselect" the previous sheets.

I want True only on the first worksheet in that group--when (ictr =
mylimit
+ 1)

mylimit = 2

Then ictr = 3 (the first of the group).

The next time through, ictr will be 4
4 is different from mylimit + 1 (=3) so it evaluates to False--and so
that
second (and all subsequent sheets get added to the group.


Thanks again Dave.

  #7   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 121
Default select sheets

The magic is not knowing what TRUE/FALSE does as an argument to the Select
method, but it is the elegant way of not having to set up if ... else ....
end if clause to separate treatment. I am going to be on the lookout for
opportunities to do that when an T/F argument varies under two mutually
exclusive conditions like shown ... i.e., something either IS or IS NOT =
Mylimit.

Beautiful.



"snax500" wrote in message
oups.com...
It really is. I wrote to Dave for an explanation. Here it is...



Take a look at help for .select.

It has an option to replace the selected sheet or keep adding.

False means that it's just "added" to the current group of selected
sheets.

True means to select that sheet and "unselect" the previous sheets.

I want True only on the first worksheet in that group--when (ictr =
mylimit
+ 1)

mylimit = 2

Then ictr = 3 (the first of the group).

The next time through, ictr will be 4
4 is different from mylimit + 1 (=3) so it evaluates to False--and so
that
second (and all subsequent sheets get added to the group.


Thanks again Dave.



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
macro to select all sheets belvy123 Excel Discussion (Misc queries) 1 March 26th 08 04:23 PM
How to select other sheets using ADO farmer[_2_] Excel Programming 2 October 24th 04 06:56 PM
select a1 on all sheets Piers Clinton-Tarestad Excel Programming 1 October 1st 03 08:34 PM
All Sheets Unhide and Select Hande & Tolga Excel Programming 2 September 11th 03 02:16 PM
select sheets by name - how? Walt[_2_] Excel Programming 5 July 30th 03 10:42 PM


All times are GMT +1. The time now is 09:05 AM.

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

About Us

"It's about Microsoft Excel"