Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 4
Default looping through selected sheet tabs

I am trying to write a program to go through just the
selected sheets in a workbook and then loop through the
selected cells in each sheet.


Sub Replace2()
Dim c As Object, sht As Worksheet
For Each sht In 'Is there a way to get an array of
'the sheets that are selected.

For Each c In sht.Selection 'I thought this is how
'you get the range of
'selected cells.
Debug.Print c
Next c
Next sht
End Sub

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 146
Default looping through selected sheet tabs

Gary -

For Each sht in ActiveWorkbook.Worksheets

If you are going to work on the selected range, you need to activate each sheet
first. Do you want the same range on every sheet? Then do something like this on the
first sheet:

Dim sRng as string
Dim c as range

If Typename(Selection) = "Range" then
sRng = selection.address
End If

' in the loop...
For each c in sht.Range(sRng)

- Jon
-------
Jon Peltier, Microsoft Excel MVP
Peltier Technical Services
Tutorials and Custom Solutions
http://PeltierTech.com/
_______


Gary Adamson wrote:

I am trying to write a program to go through just the
selected sheets in a workbook and then loop through the
selected cells in each sheet.


Sub Replace2()
Dim c As Object, sht As Worksheet
For Each sht In 'Is there a way to get an array of
'the sheets that are selected.

For Each c In sht.Selection 'I thought this is how
'you get the range of
'selected cells.
Debug.Print c
Next c
Next sht
End Sub


  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default looping through selected sheet tabs

Gary

If you want to "hard code" your sheet selection then you can use

Dim Sh As Worksheet
For Each Sh In Sheets(Array("Sheet1", "Sheet2", "Sheet3"))
'your code here
Next

Alternatively, if you want to use the currently selected sheets then
you can use

Dim Sh As Worksheet
For Each Sh In ActiveWindow.SelectedSheets
'your code here
Next

Peter

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 42
Default looping through selected sheet tabs

Assuming you have previously selected ranges in each of your sheets, try:


Dim Sh As Worksheet
dim c as Range
For Each Sh In ActiveWindow.SelectedSheets
For each c in Selection
'your code
Next c
Next Sh



" wrote:

Gary

If you want to "hard code" your sheet selection then you can use

Dim Sh As Worksheet
For Each Sh In Sheets(Array("Sheet1", "Sheet2", "Sheet3"))
'your code here
Next

Alternatively, if you want to use the currently selected sheets then
you can use

Dim Sh As Worksheet
For Each Sh In ActiveWindow.SelectedSheets
'your code here
Next

Peter


  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 146
Default looping through selected sheet tabs

If you do not change the active sheet, the selection remains whatever is selected on
the real active sheet. I ran these one-line loops in the debug window, with a two
worksheet workbook.

Without activating each sheet, the selected range is unchanged:

for each ws in worksheets : debug.Print selection.address(external:=true) : next
[Book1]Sheet1!$A$1:$C$3
[Book1]Sheet1!$A$1:$C$3

activating the sheet causes its selected area to become the selection:

for each ws in worksheets : ws.activate : debug.Print
selection.address(external:=true) : next
[Book1]Sheet1!$A$1:$C$3
[Book1]Sheet2!$D$4:$F$6

- Jon
-------
Jon Peltier, Microsoft Excel MVP
Peltier Technical Services
Tutorials and Custom Solutions
http://PeltierTech.com/
_______


gocush wrote:

Assuming you have previously selected ranges in each of your sheets, try:


Dim Sh As Worksheet
dim c as Range
For Each Sh In ActiveWindow.SelectedSheets
For each c in Selection
'your code
Next c
Next Sh



" wrote:


Gary

If you want to "hard code" your sheet selection then you can use

Dim Sh As Worksheet
For Each Sh In Sheets(Array("Sheet1", "Sheet2", "Sheet3"))
'your code here
Next

Alternatively, if you want to use the currently selected sheets then
you can use

Dim Sh As Worksheet
For Each Sh In ActiveWindow.SelectedSheets
'your code here
Next

Peter



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
tabs are missing even though 'tools-options-view-sheet tabs' ok? rgranell Excel Worksheet Functions 3 August 16th 08 04:25 PM
Printing Selected Sheet Tabs billbrandi Excel Discussion (Misc queries) 1 October 18th 07 12:36 AM
Email selected tabs of spreadsheet? DrWilki Excel Discussion (Misc queries) 4 August 29th 07 01:27 PM
how do i make it so that when a sheat is selected either via link or tab, that xlLastCell is selected. the last on the sheet. Daniel Excel Worksheet Functions 1 July 12th 05 01:30 AM
Hide selected worksheet tabs J. T. SYLVESTER SR. Excel Programming 1 December 2nd 04 02:45 AM


All times are GMT +1. The time now is 04:58 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"