Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 45
Default Choose several sheets in VBA

Hi,
I'm trying to learn VBA and I need some help with this:
The code below makes the sheets 4 and more to be selected up to the last
sheet in the workbook.
Can anyone give me help to create a code that select sheet 4 to 9 in a
workbook with more than 9 sheets.
I mean, how to get that array in the workbook?

Dim sheetArray() As Integer
Dim firstSheet As Integer, sheetCount As Integer, x As Integer
firstSheet = 4
sheetCount = ThisWorkbook.WorkSheets.Count - firstSheet
ReDim sheetArray(sheetCount)
For x = 0 To sheetCount
sheetArray(x) = firstSheet + x
Next x
ThisWorkbook.WorkSheets(sheetArray).Select


Thanks in advance!

//Thomas


  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,302
Default Choose several sheets in VBA

Hi Jonnson.

Try:

ActiveWorkbook.Sheets(Array("Sheet4", "Sheet5", "Sheet6", _
"Sheet7", "Sheet8", "Sheet9")).Select

---
Regards,
Norman



"Jonsson" wrote in message
...
Hi,
I'm trying to learn VBA and I need some help with this:
The code below makes the sheets 4 and more to be selected up to the last
sheet in the workbook.
Can anyone give me help to create a code that select sheet 4 to 9 in a
workbook with more than 9 sheets.
I mean, how to get that array in the workbook?

Dim sheetArray() As Integer
Dim firstSheet As Integer, sheetCount As Integer, x As Integer
firstSheet = 4
sheetCount = ThisWorkbook.WorkSheets.Count - firstSheet
ReDim sheetArray(sheetCount)
For x = 0 To sheetCount
sheetArray(x) = firstSheet + x
Next x
ThisWorkbook.WorkSheets(sheetArray).Select


Thanks in advance!

//Thomas




  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default Choose several sheets in VBA

Or more general

ActiveWorkbook.worksheets(Array(4,5,6,7,8,9)).Sele ct

--
Regards,
Tom Ogilvy



"Norman Jones" wrote in message
...
Hi Jonnson.

Try:

ActiveWorkbook.Sheets(Array("Sheet4", "Sheet5", "Sheet6", _
"Sheet7", "Sheet8", "Sheet9")).Select

---
Regards,
Norman



"Jonsson" wrote in message
...
H
I'm trying to learn VBA and I need some help with this:
The code below makes the sheets 4 and more to be selected up to the last
sheet in the workbook.
Can anyone give me help to create a code that select sheet 4 to 9 in a
workbook with more than 9 sheets.
I mean, how to get that array in the workbook?

Dim sheetArray() As Integer
Dim firstSheet As Integer, sheetCount As Integer, x As Integer
firstSheet = 4
sheetCount = ThisWorkbook.WorkSheets.Count - firstSheet
ReDim sheetArray(sheetCount)
For x = 0 To sheetCount
sheetArray(x) = firstSheet + x
Next x
ThisWorkbook.WorkSheets(sheetArray).Select


Thanks in advance!

//Thomas






  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 45
Default Choose several sheets in VBA

Hi Norman

Thanks, but that's a way I try not to do.
Actually, I have 100 sheets, imagine the look of that code!
I need a shorter code based on the one I have in this message.

"Norman Jones" skrev i meddelandet
...
Hi Jonnson.

Try:

ActiveWorkbook.Sheets(Array("Sheet4", "Sheet5", "Sheet6", _
"Sheet7", "Sheet8", "Sheet9")).Select

---
Regards,
Norman



"Jonsson" wrote in message
...
Hi,
I'm trying to learn VBA and I need some help with this:
The code below makes the sheets 4 and more to be selected up to the last
sheet in the workbook.
Can anyone give me help to create a code that select sheet 4 to 9 in a
workbook with more than 9 sheets.
I mean, how to get that array in the workbook?

Dim sheetArray() As Integer
Dim firstSheet As Integer, sheetCount As Integer, x As Integer
firstSheet = 4
sheetCount = ThisWorkbook.WorkSheets.Count - firstSheet
ReDim sheetArray(sheetCount)
For x = 0 To sheetCount
sheetArray(x) = firstSheet + x
Next x
ThisWorkbook.WorkSheets(sheetArray).Select


Thanks in advance!

//Thomas






  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,302
Default Choose several sheets in VBA

Hi Jonnson,

If you do not want to build the array in code, go with Tom's suggestion!

Incidentally, how did:

Can anyone give me help to create a code that select sheet 4 to 9


become:

Actually, I have 100 sheets


---
Regards,
Norman



"Jonsson" wrote in message
...
Hi Norman

Thanks, but that's a way I try not to do.
Actually, I have 100 sheets, imagine the look of that code!
I need a shorter code based on the one I have in this message.

"Norman Jones" skrev i meddelandet
...
Hi Jonnson.

Try:

ActiveWorkbook.Sheets(Array("Sheet4", "Sheet5", "Sheet6", _
"Sheet7", "Sheet8", "Sheet9")).Select

---
Regards,
Norman



"Jonsson" wrote in message
...
Hi,
I'm trying to learn VBA and I need some help with this:
The code below makes the sheets 4 and more to be selected up to the
last
sheet in the workbook.
Can anyone give me help to create a code that select sheet 4 to 9 in a
workbook with more than 9 sheets.
I mean, how to get that array in the workbook?

Dim sheetArray() As Integer
Dim firstSheet As Integer, sheetCount As Integer, x As Integer
firstSheet = 4
sheetCount = ThisWorkbook.WorkSheets.Count - firstSheet
ReDim sheetArray(sheetCount)
For x = 0 To sheetCount
sheetArray(x) = firstSheet + x
Next x
ThisWorkbook.WorkSheets(sheetArray).Select


Thanks in advance!

//Thomas










  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default Choose several sheets in VBA

Sub AABB()
Dim sheetArray() As Integer
Dim x as Long
Dim lastSheet as Long
Dim firstSheet as Long
Dim firstSheet As Integer, sheetCount As Integer, x As Integer
firstSheet = 4
lastSheet = 9
if lastSheet thisWorkbook.Worksheets.count then _
lastSheet = ThisWorkbook.Worksheets.count
ReDim sheetArray(0 to lastsheet - firstsheet)
For x = 0 To Ubound(SheetArray)
sheetArray(x) =FirstSheet + x
Next x
ThisWorkbook.WorkSheets(sheetArray).Select

End Sub

--
Regards,
Tom Ogilvy

"Jonsson" wrote in message
...
Hi Norman

Thanks, but that's a way I try not to do.
Actually, I have 100 sheets, imagine the look of that code!
I need a shorter code based on the one I have in this message.

"Norman Jones" skrev i meddelandet
...
Hi Jonnson.

Try:

ActiveWorkbook.Sheets(Array("Sheet4", "Sheet5", "Sheet6", _
"Sheet7", "Sheet8", "Sheet9")).Select

---
Regards,
Norman



"Jonsson" wrote in message
...
Hi,
I'm trying to learn VBA and I need some help with this:
The code below makes the sheets 4 and more to be selected up to the

last
sheet in the workbook.
Can anyone give me help to create a code that select sheet 4 to 9 in a
workbook with more than 9 sheets.
I mean, how to get that array in the workbook?

Dim sheetArray() As Integer
Dim firstSheet As Integer, sheetCount As Integer, x As Integer
firstSheet = 4
sheetCount = ThisWorkbook.WorkSheets.Count - firstSheet
ReDim sheetArray(sheetCount)
For x = 0 To sheetCount
sheetArray(x) = firstSheet + x
Next x
ThisWorkbook.WorkSheets(sheetArray).Select


Thanks in advance!

//Thomas








  #7   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default Choose several sheets in VBA

Whoops, have some double declarations

Sub AABB()
Dim sheetArray() As Long
Dim x as Long
Dim lastSheet as Long
Dim firstSheet as Long
Dim sheetcount as Long
firstSheet = 4
lastSheet = 9
if lastSheet thisWorkbook.Worksheets.count then _
lastSheet = ThisWorkbook.Worksheets.count
ReDim sheetArray(0 to lastsheet - firstsheet)
For x = 0 To Ubound(SheetArray)
sheetArray(x) =FirstSheet + x
Next x
ThisWorkbook.WorkSheets(sheetArray).Select

End Sub
--
Regards,
Tom Ogilvy



"Tom Ogilvy" wrote in message
...
Sub AABB()
Dim sheetArray() As Integer
Dim x as Long
Dim lastSheet as Long
Dim firstSheet as Long
Dim firstSheet As Integer, sheetCount As Integer, x As Integer
firstSheet = 4
lastSheet = 9
if lastSheet thisWorkbook.Worksheets.count then _
lastSheet = ThisWorkbook.Worksheets.count
ReDim sheetArray(0 to lastsheet - firstsheet)
For x = 0 To Ubound(SheetArray)
sheetArray(x) =FirstSheet + x
Next x
ThisWorkbook.WorkSheets(sheetArray).Select

End Sub

--
Regards,
Tom Ogilvy

"Jonsson" wrote in message
...
Hi Norman

Thanks, but that's a way I try not to do.
Actually, I have 100 sheets, imagine the look of that code!
I need a shorter code based on the one I have in this message.

"Norman Jones" skrev i meddelandet
...
Hi Jonnson.

Try:

ActiveWorkbook.Sheets(Array("Sheet4", "Sheet5", "Sheet6", _
"Sheet7", "Sheet8", "Sheet9")).Select

---
Regards,
Norman



"Jonsson" wrote in message
...
Hi,
I'm trying to learn VBA and I need some help with this:
The code below makes the sheets 4 and more to be selected up to the

last
sheet in the workbook.
Can anyone give me help to create a code that select sheet 4 to 9 in

a
workbook with more than 9 sheets.
I mean, how to get that array in the workbook?

Dim sheetArray() As Integer
Dim firstSheet As Integer, sheetCount As Integer, x As Integer
firstSheet = 4
sheetCount = ThisWorkbook.WorkSheets.Count - firstSheet
ReDim sheetArray(sheetCount)
For x = 0 To sheetCount
sheetArray(x) = firstSheet + x
Next x
ThisWorkbook.WorkSheets(sheetArray).Select


Thanks in advance!

//Thomas










  #8   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 45
Default Choose several sheets in VBA

Hi, Norman!

It was just an example, to give you guys a hint of what I meant to do!

And Tom!

Thats the one!! GREAT!!

Thanks both of you, for the effort to help me!

//Thomas


"Tom Ogilvy" skrev i meddelandet
...
Sub AABB()
Dim sheetArray() As Integer
Dim x as Long
Dim lastSheet as Long
Dim firstSheet as Long
Dim firstSheet As Integer, sheetCount As Integer, x As Integer
firstSheet = 4
lastSheet = 9
if lastSheet thisWorkbook.Worksheets.count then _
lastSheet = ThisWorkbook.Worksheets.count
ReDim sheetArray(0 to lastsheet - firstsheet)
For x = 0 To Ubound(SheetArray)
sheetArray(x) =FirstSheet + x
Next x
ThisWorkbook.WorkSheets(sheetArray).Select

End Sub

--
Regards,
Tom Ogilvy

"Jonsson" wrote in message
...
Hi Norman

Thanks, but that's a way I try not to do.
Actually, I have 100 sheets, imagine the look of that code!
I need a shorter code based on the one I have in this message.

"Norman Jones" skrev i meddelandet
...
Hi Jonnson.

Try:

ActiveWorkbook.Sheets(Array("Sheet4", "Sheet5", "Sheet6", _
"Sheet7", "Sheet8", "Sheet9")).Select

---
Regards,
Norman



"Jonsson" wrote in message
...
Hi,
I'm trying to learn VBA and I need some help with this:
The code below makes the sheets 4 and more to be selected up to the

last
sheet in the workbook.
Can anyone give me help to create a code that select sheet 4 to 9 in

a
workbook with more than 9 sheets.
I mean, how to get that array in the workbook?

Dim sheetArray() As Integer
Dim firstSheet As Integer, sheetCount As Integer, x As Integer
firstSheet = 4
sheetCount = ThisWorkbook.WorkSheets.Count - firstSheet
ReDim sheetArray(sheetCount)
For x = 0 To sheetCount
sheetArray(x) = firstSheet + x
Next x
ThisWorkbook.WorkSheets(sheetArray).Select


Thanks in advance!

//Thomas










  #9   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 690
Default Choose several sheets in VBA

I'm trying to learn VBA

Just to give you another idea since it wasn't mentioned. This just selects
the sheets.

Sub Demo()
Dim j As Long

'Replace with this one sheet
Sheets(4).Select True

For j = 4 To 9
'Don't replace, but "Add" to Selection
Sheets(j).Select False
Next j
End Sub

Consider using "Worksheets" instead of "Sheets" if you wish to avoid
selecting any "Chart Sheets" and "Excel4 Macro Sheets"

HTH
Dana DeLouis



"Jonsson" wrote in message
...
Hi, Norman!

It was just an example, to give you guys a hint of what I meant to do!

And Tom!

Thats the one!! GREAT!!

Thanks both of you, for the effort to help me!

//Thomas


"Tom Ogilvy" skrev i meddelandet
...
Sub AABB()
Dim sheetArray() As Integer
Dim x as Long
Dim lastSheet as Long
Dim firstSheet as Long
Dim firstSheet As Integer, sheetCount As Integer, x As Integer
firstSheet = 4
lastSheet = 9
if lastSheet thisWorkbook.Worksheets.count then _
lastSheet = ThisWorkbook.Worksheets.count
ReDim sheetArray(0 to lastsheet - firstsheet)
For x = 0 To Ubound(SheetArray)
sheetArray(x) =FirstSheet + x
Next x
ThisWorkbook.WorkSheets(sheetArray).Select

End Sub

--
Regards,
Tom Ogilvy

"Jonsson" wrote in message
...
Hi Norman

Thanks, but that's a way I try not to do.
Actually, I have 100 sheets, imagine the look of that code!
I need a shorter code based on the one I have in this message.

"Norman Jones" skrev i meddelandet
...
Hi Jonnson.

Try:

ActiveWorkbook.Sheets(Array("Sheet4", "Sheet5", "Sheet6", _
"Sheet7", "Sheet8", "Sheet9")).Select

---
Regards,
Norman



"Jonsson" wrote in message
...
Hi,
I'm trying to learn VBA and I need some help with this:
The code below makes the sheets 4 and more to be selected up to the

last
sheet in the workbook.
Can anyone give me help to create a code that select sheet 4 to 9
in

a
workbook with more than 9 sheets.
I mean, how to get that array in the workbook?

Dim sheetArray() As Integer
Dim firstSheet As Integer, sheetCount As Integer, x As Integer
firstSheet = 4
sheetCount = ThisWorkbook.WorkSheets.Count - firstSheet
ReDim sheetArray(sheetCount)
For x = 0 To sheetCount
sheetArray(x) = firstSheet + x
Next x
ThisWorkbook.WorkSheets(sheetArray).Select


Thanks in advance!

//Thomas












  #10   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 690
Default Choose several sheets in VBA

Actually, I kind of like this version. The j=4 part returns True / False

Sub Demo()
Dim j As Long
For j = 4 To 9
Worksheets(j).Select (j = 4)
Next j
End Sub

HTH
Dana DeLouis


"Dana DeLouis" wrote in message
...
I'm trying to learn VBA


Just to give you another idea since it wasn't mentioned. This just
selects the sheets.

Sub Demo()
Dim j As Long

'Replace with this one sheet
Sheets(4).Select True

For j = 4 To 9
'Don't replace, but "Add" to Selection
Sheets(j).Select False
Next j
End Sub

Consider using "Worksheets" instead of "Sheets" if you wish to avoid
selecting any "Chart Sheets" and "Excel4 Macro Sheets"

HTH
Dana DeLouis



"Jonsson" wrote in message
...
Hi, Norman!

It was just an example, to give you guys a hint of what I meant to do!

And Tom!

Thats the one!! GREAT!!

Thanks both of you, for the effort to help me!

//Thomas


"Tom Ogilvy" skrev i meddelandet
...
Sub AABB()
Dim sheetArray() As Integer
Dim x as Long
Dim lastSheet as Long
Dim firstSheet as Long
Dim firstSheet As Integer, sheetCount As Integer, x As Integer
firstSheet = 4
lastSheet = 9
if lastSheet thisWorkbook.Worksheets.count then _
lastSheet = ThisWorkbook.Worksheets.count
ReDim sheetArray(0 to lastsheet - firstsheet)
For x = 0 To Ubound(SheetArray)
sheetArray(x) =FirstSheet + x
Next x
ThisWorkbook.WorkSheets(sheetArray).Select

End Sub

--
Regards,
Tom Ogilvy

"Jonsson" wrote in message
...
Hi Norman

Thanks, but that's a way I try not to do.
Actually, I have 100 sheets, imagine the look of that code!
I need a shorter code based on the one I have in this message.

"Norman Jones" skrev i meddelandet
...
Hi Jonnson.

Try:

ActiveWorkbook.Sheets(Array("Sheet4", "Sheet5", "Sheet6", _
"Sheet7", "Sheet8", "Sheet9")).Select

---
Regards,
Norman



"Jonsson" wrote in message
...
Hi,
I'm trying to learn VBA and I need some help with this:
The code below makes the sheets 4 and more to be selected up to
the
last
sheet in the workbook.
Can anyone give me help to create a code that select sheet 4 to 9
in

a
workbook with more than 9 sheets.
I mean, how to get that array in the workbook?

Dim sheetArray() As Integer
Dim firstSheet As Integer, sheetCount As Integer, x As Integer
firstSheet = 4
sheetCount = ThisWorkbook.WorkSheets.Count - firstSheet
ReDim sheetArray(sheetCount)
For x = 0 To sheetCount
sheetArray(x) = firstSheet + x
Next x
ThisWorkbook.WorkSheets(sheetArray).Select


Thanks in advance!

//Thomas





  #11   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 45
Default Choose several sheets in VBA

Hi Dana,

Thanks for your angle, I'm learning new things all the time.

//Thomas


"Dana DeLouis" skrev i meddelandet
...
Actually, I kind of like this version. The j=4 part returns True / False

Sub Demo()
Dim j As Long
For j = 4 To 9
Worksheets(j).Select (j = 4)
Next j
End Sub

HTH
Dana DeLouis


"Dana DeLouis" wrote in message
...
I'm trying to learn VBA


Just to give you another idea since it wasn't mentioned. This just
selects the sheets.

Sub Demo()
Dim j As Long

'Replace with this one sheet
Sheets(4).Select True

For j = 4 To 9
'Don't replace, but "Add" to Selection
Sheets(j).Select False
Next j
End Sub

Consider using "Worksheets" instead of "Sheets" if you wish to avoid
selecting any "Chart Sheets" and "Excel4 Macro Sheets"

HTH
Dana DeLouis



"Jonsson" wrote in message
...
Hi, Norman!

It was just an example, to give you guys a hint of what I meant to do!

And Tom!

Thats the one!! GREAT!!

Thanks both of you, for the effort to help me!

//Thomas


"Tom Ogilvy" skrev i meddelandet
...
Sub AABB()
Dim sheetArray() As Integer
Dim x as Long
Dim lastSheet as Long
Dim firstSheet as Long
Dim firstSheet As Integer, sheetCount As Integer, x As Integer
firstSheet = 4
lastSheet = 9
if lastSheet thisWorkbook.Worksheets.count then _
lastSheet = ThisWorkbook.Worksheets.count
ReDim sheetArray(0 to lastsheet - firstsheet)
For x = 0 To Ubound(SheetArray)
sheetArray(x) =FirstSheet + x
Next x
ThisWorkbook.WorkSheets(sheetArray).Select

End Sub

--
Regards,
Tom Ogilvy

"Jonsson" wrote in message
...
Hi Norman

Thanks, but that's a way I try not to do.
Actually, I have 100 sheets, imagine the look of that code!
I need a shorter code based on the one I have in this message.

"Norman Jones" skrev i meddelandet
...
Hi Jonnson.

Try:

ActiveWorkbook.Sheets(Array("Sheet4", "Sheet5", "Sheet6", _
"Sheet7", "Sheet8", "Sheet9")).Select

---
Regards,
Norman



"Jonsson" wrote in message
...
Hi,
I'm trying to learn VBA and I need some help with this:
The code below makes the sheets 4 and more to be selected up to
the
last
sheet in the workbook.
Can anyone give me help to create a code that select sheet 4 to

9
in
a
workbook with more than 9 sheets.
I mean, how to get that array in the workbook?

Dim sheetArray() As Integer
Dim firstSheet As Integer, sheetCount As Integer, x As

Integer
firstSheet = 4
sheetCount = ThisWorkbook.WorkSheets.Count - firstSheet
ReDim sheetArray(sheetCount)
For x = 0 To sheetCount
sheetArray(x) = firstSheet + x
Next x
ThisWorkbook.WorkSheets(sheetArray).Select


Thanks in advance!

//Thomas





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
Getting a Sheet to Choose to Display Other Sheets Kyle P.[_2_] Excel Discussion (Misc queries) 0 May 27th 10 10:57 PM
Switching between sheets in same workbook (Like Alt + Tab & Choose nils Excel Discussion (Misc queries) 4 April 17th 10 12:12 AM
choose. pierre Excel Discussion (Misc queries) 2 April 25th 08 10:04 PM
choose? pierre Excel Discussion (Misc queries) 2 April 24th 08 09:47 PM
Choose. Rodney New Users to Excel 2 May 2nd 05 04:59 AM


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