Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 441
Default Array of all selected sheet names?

I am using Office 2003 on Windows XP.

Situation:
The user has more than one sheet selected.

Programmatically I need:
An array of one column by multiple rows of the names of all the selected
sheets.

Could someone please post an efficient method of obtaining this?
Thanks much in advance.
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 4,624
Default Array of all selected sheet names?

One way:

Dim i As Long
With ActiveWindow.SelectedSheets
For i = 1 To .Count
Cells(i, 1).Value = .Item(i).Name
Next i
End With


In article ,
quartz wrote:

I am using Office 2003 on Windows XP.

Situation:
The user has more than one sheet selected.

Programmatically I need:
An array of one column by multiple rows of the names of all the selected
sheets.

Could someone please post an efficient method of obtaining this?
Thanks much in advance.

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 535
Default Array of all selected sheet names?

Hi JE,

One way:

Dim i As Long
With ActiveWindow.SelectedSheets
For i = 1 To .Count
Cells(i, 1).Value = .Item(i).Name
Next i
End With


Wouldn't that put the list in all selected sheets (since they are
grouped)?

Regards,

Jan Karel Pieterse
Excel MVP
http://www.jkp-ads.com

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default Array of all selected sheet names?

No, it would place the entry in the activesheet. VBA doesn't support
processing sheets as a group for the most part. This is one of those parts.

--
Regards,
Tom Ogilvy

"Jan Karel Pieterse" wrote in message
...
Hi JE,

One way:

Dim i As Long
With ActiveWindow.SelectedSheets
For i = 1 To .Count
Cells(i, 1).Value = .Item(i).Name
Next i
End With


Wouldn't that put the list in all selected sheets (since they are
grouped)?

Regards,

Jan Karel Pieterse
Excel MVP
http://www.jkp-ads.com



  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 4,624
Default Array of all selected sheet names?

In article ,
Jan Karel Pieterse wrote:

Wouldn't that put the list in all selected sheets (since they are
grouped)?


True.


  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 4,624
Default Array of all selected sheet names?

In article ,
JE McGimpsey wrote:

In article ,
Jan Karel Pieterse wrote:

Wouldn't that put the list in all selected sheets (since they are
grouped)?


True.


Danged Send Key!

True. They're grouped. But VBA can't write to more than one sheet at a
time.
  #7   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 535
Default Array of all selected sheet names?

Hi JE,

True. They're grouped. But VBA can't write to more than one sheet at a
time.


I suspected that, but was too lazy to test myself <g.

Regards,

Jan Karel Pieterse
Excel MVP
http://www.jkp-ads.com

  #8   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 441
Default Array of all selected sheet names?

Jan is right of course, but I figured it out...I could not come up with
the "ActiveWindow.SelectedSheets" part. Thanks for the help.

"JE McGimpsey" wrote:

One way:

Dim i As Long
With ActiveWindow.SelectedSheets
For i = 1 To .Count
Cells(i, 1).Value = .Item(i).Name
Next i
End With


In article ,
quartz wrote:

I am using Office 2003 on Windows XP.

Situation:
The user has more than one sheet selected.

Programmatically I need:
An array of one column by multiple rows of the names of all the selected
sheets.

Could someone please post an efficient method of obtaining this?
Thanks much in advance.


  #9   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 535
Default Array of all selected sheet names?

Hi Quartz,

Programmatically I need:
An array of one column by multiple rows of the names of all the selected
sheets.


Sub test()
Dim osh As Object
Dim sSheetnames() As String
ReDim sSheetnames(1)
Dim lCount As Long
For Each osh In ActiveWindow.SelectedSheets
lCount = lCount + 1
ReDim sSheetnames(lCount)
sSheetnames(lCount) = osh.Name
Next

End Sub


Regards,

Jan Karel Pieterse
Excel MVP
http://www.jkp-ads.com

  #10   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 441
Default Array of all selected sheet names?

Perfect, thanks a lot!

"Jan Karel Pieterse" wrote:

Hi Quartz,

Programmatically I need:
An array of one column by multiple rows of the names of all the selected
sheets.


Sub test()
Dim osh As Object
Dim sSheetnames() As String
ReDim sSheetnames(1)
Dim lCount As Long
For Each osh In ActiveWindow.SelectedSheets
lCount = lCount + 1
ReDim sSheetnames(lCount)
sSheetnames(lCount) = osh.Name
Next

End Sub


Regards,

Jan Karel Pieterse
Excel MVP
http://www.jkp-ads.com




  #11   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 279
Default Array of all selected sheet names?

Look at my first post

I think Jan forgot the Redim PRESERVE
which expands the array WITHOUT deleting the existing information

"quartz" wrote:

Perfect, thanks a lot!

"Jan Karel Pieterse" wrote:

Hi Quartz,

Programmatically I need:
An array of one column by multiple rows of the names of all the selected
sheets.


Sub test()
Dim osh As Object
Dim sSheetnames() As String
ReDim sSheetnames(1)
Dim lCount As Long
For Each osh In ActiveWindow.SelectedSheets
lCount = lCount + 1
ReDim sSheetnames(lCount)
sSheetnames(lCount) = osh.Name
Next

End Sub


Regards,

Jan Karel Pieterse
Excel MVP
http://www.jkp-ads.com


  #12   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 279
Default Array of all selected sheet names?

OK, OK and I forgot the selected sheets part of the question.
Add Preserve to jan's reDim code

"Vacation's Over" wrote:

Look at my first post

I think Jan forgot the Redim PRESERVE
which expands the array WITHOUT deleting the existing information

"quartz" wrote:

Perfect, thanks a lot!

"Jan Karel Pieterse" wrote:

Hi Quartz,

Programmatically I need:
An array of one column by multiple rows of the names of all the selected
sheets.

Sub test()
Dim osh As Object
Dim sSheetnames() As String
ReDim sSheetnames(1)
Dim lCount As Long
For Each osh In ActiveWindow.SelectedSheets
lCount = lCount + 1
ReDim sSheetnames(lCount)
sSheetnames(lCount) = osh.Name
Next

End Sub


Regards,

Jan Karel Pieterse
Excel MVP
http://www.jkp-ads.com


  #13   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 535
Default Array of all selected sheet names?

Hi Vacation's,

I think Jan forgot the Redim PRESERVE


Yup, well spotted.

Regards,

Jan Karel Pieterse
Excel MVP
http://www.jkp-ads.com

  #14   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 279
Default Array of all selected sheet names?

Function aryAirCode()as Variant

dim wks as Worksheet
Dim counter as long
Dim buf() as String

conter = 1

For each wks in Activeworkbook.Sheets
redim preserve buf(1 to counter)
buf(counter) = wks.Name
counter = counter+1
next wks

aryAirCode = buf
end function

sub YOURCODEBLOCK()
dim Your variable for the array as Variant
'yourcode
Your variable for the array = aryAirCode()
'yourcode

end YOURCODEBLOCK sub


"quartz" wrote:

I am using Office 2003 on Windows XP.

Situation:
The user has more than one sheet selected.

Programmatically I need:
An array of one column by multiple rows of the names of all the selected
sheets.

Could someone please post an efficient method of obtaining this?
Thanks much in advance.

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
XL2007 and array of sheet names? Jack Sheet Excel Discussion (Misc queries) 0 August 5th 06 02:57 PM
get all sheet names in comboBox of activeworkbook and export when selected ilyaskazi[_26_] Excel Programming 5 June 14th 05 02:49 PM
Load an array with Sheet names S G Booth Excel Programming 6 March 2nd 05 08:48 PM
Sheet Names Array Rocky McKinley Excel Programming 2 June 9th 04 11:49 PM
Place selected object names into array Tristan[_2_] Excel Programming 0 April 14th 04 10:36 AM


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