Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Dr.Schwartz
 
Posts: n/a
Default Selecting sheets - II

Yesterday Bob Phillips kindly supplied me with code to select multible sheets.

Now I need to run some code on each of the selected sheets - but how? This
is what I have come up with so far (but is not working):

Dim WSS As Worksheet
For Each WSS In Application.Selection
'my code
Next

Suggestions? Thanks / The Doctor

  #2   Report Post  
Dave Peterson
 
Posts: n/a
Default


dim wss as worksheet
For each wss in activewindow.selectedsheets
'your code
next wss

If they've already been selected.

Dr.Schwartz wrote:

Yesterday Bob Phillips kindly supplied me with code to select multible sheets.

Now I need to run some code on each of the selected sheets - but how? This
is what I have come up with so far (but is not working):

Dim WSS As Worksheet
For Each WSS In Application.Selection
'my code
Next

Suggestions? Thanks / The Doctor


--

Dave Peterson
  #3   Report Post  
Dr.Schwartz
 
Posts: n/a
Default

I was to fast ticking this one off as OK.

The problem is even though I select more than one sheet the code only takes
effect on the highlighted of the selected sheets. But the code does run as
many times as there are sheets selected.

How can I make it take effect on all selected sheets?

The Doctor

"Dave Peterson" wrote:


dim wss as worksheet
For each wss in activewindow.selectedsheets
'your code
next wss

If they've already been selected.

Dr.Schwartz wrote:

Yesterday Bob Phillips kindly supplied me with code to select multible sheets.

Now I need to run some code on each of the selected sheets - but how? This
is what I have come up with so far (but is not working):

Dim WSS As Worksheet
For Each WSS In Application.Selection
'my code
Next

Suggestions? Thanks / The Doctor


--

Dave Peterson

  #4   Report Post  
Dave Peterson
 
Posts: n/a
Default

My bet is your code refers to the active sheet.

One way is to replace the activesheet reference with wss.

Another way is to just activate that sheet.

dim wss as worksheet
for each wss in activewindows.selectedsheets
with wss
.range("a1").value = "hi there!"
end with
next wss

or

dim wss as worksheet
for each wss in activewindows.selectedsheets
wss.activate
activesheet.range("a1").value = "hi there!"
next wss

Personally, I like the first option.

If you have trouble, you're gonna have to post more of your code.

Dr.Schwartz wrote:

I was to fast ticking this one off as OK.

The problem is even though I select more than one sheet the code only takes
effect on the highlighted of the selected sheets. But the code does run as
many times as there are sheets selected.

How can I make it take effect on all selected sheets?

The Doctor

"Dave Peterson" wrote:


dim wss as worksheet
For each wss in activewindow.selectedsheets
'your code
next wss

If they've already been selected.

Dr.Schwartz wrote:

Yesterday Bob Phillips kindly supplied me with code to select multible sheets.

Now I need to run some code on each of the selected sheets - but how? This
is what I have come up with so far (but is not working):

Dim WSS As Worksheet
For Each WSS In Application.Selection
'my code
Next

Suggestions? Thanks / The Doctor


--

Dave Peterson


--

Dave Peterson
  #5   Report Post  
Dr.Schwartz
 
Posts: n/a
Default

Hi Dave

I guess you won this bet. I would also prefer the first solution, but since
my code already contains several With statements I will go with the second
solution.

Thank you for your patience / The Doctor

"Dave Peterson" wrote:

My bet is your code refers to the active sheet.

One way is to replace the activesheet reference with wss.

Another way is to just activate that sheet.

dim wss as worksheet
for each wss in activewindows.selectedsheets
with wss
.range("a1").value = "hi there!"
end with
next wss

or

dim wss as worksheet
for each wss in activewindows.selectedsheets
wss.activate
activesheet.range("a1").value = "hi there!"
next wss

Personally, I like the first option.

If you have trouble, you're gonna have to post more of your code.

Dr.Schwartz wrote:

I was to fast ticking this one off as OK.

The problem is even though I select more than one sheet the code only takes
effect on the highlighted of the selected sheets. But the code does run as
many times as there are sheets selected.

How can I make it take effect on all selected sheets?

The Doctor

"Dave Peterson" wrote:


dim wss as worksheet
For each wss in activewindow.selectedsheets
'your code
next wss

If they've already been selected.

Dr.Schwartz wrote:

Yesterday Bob Phillips kindly supplied me with code to select multible sheets.

Now I need to run some code on each of the selected sheets - but how? This
is what I have come up with so far (but is not working):

Dim WSS As Worksheet
For Each WSS In Application.Selection
'my code
Next

Suggestions? Thanks / The Doctor

--

Dave Peterson


--

Dave Peterson

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
Selecting sheets Dr.Schwartz Excel Discussion (Misc queries) 4 July 14th 05 01:49 PM
Copying multiple sheets from one book 2 another and undertake spec Pank Mehta Excel Discussion (Misc queries) 14 March 16th 05 04:41 PM
calculating excel spreadsheet files for pensions and life insurance (including age calculation sheets) RICHARD Excel Worksheet Functions 1 March 15th 05 05:49 PM
PROTECTING/UNPROTECTING SHEETS Maureen Excel Discussion (Misc queries) 1 January 6th 05 06:46 PM
Multiple sheets selected twa14 Excel Discussion (Misc queries) 2 December 21st 04 11:15 AM


All times are GMT +1. The time now is 05:38 PM.

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"