View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.programming
Norman Jones Norman Jones is offline
external usenet poster
 
Posts: 5,302
Default Selecting sheets with unique names

Hi Donkin,

You can refer to a sequential sheet by using its index property. Thus the
first sheet will be sheets(1) and the nth sheet will be sheets(n).

One way of iterating though the workbook's worksheets would be:

Dim SH As Worksheet

For Each SH In ActiveWorkbook.Worksheets
'your code
Next SH

If you wish to refer to specific sheets, independently of the sheet's name
or position, try using the sheet's codename property, e.g: Sheet1, Sheet2
etc. For more information see CodeName property in VBA help.


---
Regards,
Norman



"Donkin" wrote in
message ...

I am trying to write a macro which opens a workbook, selects data and
copies it to another workbook. This is to list outstanding items.

My problem is the workbook has various sheet names, the workbook is
updated regularly and I do not have control of the sheet names.

I would like to have something along the lines of

-Open workbook (I can do this)- :)
Select First Sheet (unknown name)
-Select/ Copy/ Paste Information (I can do this)- :)
Select Second Sheet (unknown name)
-etc etc etc-

The next problem is as records are added or removed so the number of
sheets varies. I need something that will start at the first sheet and
continue on to the last without specifically indicating the number of
sheets.

Any help would be greatly appreciated as I do this manually at present


--
Donkin
------------------------------------------------------------------------
Donkin's Profile:
http://www.excelforum.com/member.php...o&userid=23715
View this thread: http://www.excelforum.com/showthread...hreadid=482732