ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Selecting Worksheet Array (https://www.excelbanter.com/excel-programming/362855-selecting-worksheet-array.html)

Jeff

Selecting Worksheet Array
 
Hello,

My workbook has a first sheet that is always the same. I then have VBA that
imports new sheets from workbooks in another folder. I wish to do something
to all those sheets once brought in, but not the first. Of course the number
of sheets (and their names) varies....

How do select a sheet array that automatically starts with the second sheet
and selects all those after it? In other words, how do I select all
worksheets except sheet 1 (not knowing their names or the number)?

Thanks

Norman Jones

Selecting Worksheet Array
 
Hi Jeff,

One way:

'=============
Public Sub Tester()
Dim i As Long

For i = 2 To ThisWorkbook.Sheets.Count
Sheets(i).Select Replace:=False
Next i

End Sub
'<<=============


---
Regards,
Norman



"JEFF" wrote in message
...
Hello,

My workbook has a first sheet that is always the same. I then have VBA
that
imports new sheets from workbooks in another folder. I wish to do
something
to all those sheets once brought in, but not the first. Of course the
number
of sheets (and their names) varies....

How do select a sheet array that automatically starts with the second
sheet
and selects all those after it? In other words, how do I select all
worksheets except sheet 1 (not knowing their names or the number)?

Thanks




Dave Peterson

Selecting Worksheet Array
 
One way:

Option Explicit
Sub testme()
Dim iCtr As Long
For iCtr = 2 To Sheets.Count
Sheets(iCtr).Select Replace:=CBool(iCtr = 2)
Next iCtr
End Sub




JEFF wrote:

Hello,

My workbook has a first sheet that is always the same. I then have VBA that
imports new sheets from workbooks in another folder. I wish to do something
to all those sheets once brought in, but not the first. Of course the number
of sheets (and their names) varies....

How do select a sheet array that automatically starts with the second sheet
and selects all those after it? In other words, how do I select all
worksheets except sheet 1 (not knowing their names or the number)?

Thanks


--

Dave Peterson

Dave Peterson

Selecting Worksheet Array
 
Watchout if sheets(1) is the selected sheet.

Norman Jones wrote:

Hi Jeff,

One way:

'=============
Public Sub Tester()
Dim i As Long

For i = 2 To ThisWorkbook.Sheets.Count
Sheets(i).Select Replace:=False
Next i

End Sub
'<<=============

---
Regards,
Norman

"JEFF" wrote in message
...
Hello,

My workbook has a first sheet that is always the same. I then have VBA
that
imports new sheets from workbooks in another folder. I wish to do
something
to all those sheets once brought in, but not the first. Of course the
number
of sheets (and their names) varies....

How do select a sheet array that automatically starts with the second
sheet
and selects all those after it? In other words, how do I select all
worksheets except sheet 1 (not knowing their names or the number)?

Thanks


--

Dave Peterson

Norman Jones

Selecting Worksheet Array
 
Hi Dave,

Watchout if sheets(1) is the selected sheet.



Very true, thank you!

---
Regards,
Norman





Jeff

Selecting Worksheet Array
 
That works.... thank you

"Dave Peterson" wrote:

One way:

Option Explicit
Sub testme()
Dim iCtr As Long
For iCtr = 2 To Sheets.Count
Sheets(iCtr).Select Replace:=CBool(iCtr = 2)
Next iCtr
End Sub




JEFF wrote:

Hello,

My workbook has a first sheet that is always the same. I then have VBA that
imports new sheets from workbooks in another folder. I wish to do something
to all those sheets once brought in, but not the first. Of course the number
of sheets (and their names) varies....

How do select a sheet array that automatically starts with the second sheet
and selects all those after it? In other words, how do I select all
worksheets except sheet 1 (not knowing their names or the number)?

Thanks


--

Dave Peterson



All times are GMT +1. The time now is 12:40 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com