Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 4
Default macro to select sheets

Hi,

I need to select an array of sheets, starting from the
first sheet to a sheet before the sheet "Acc". What is
the code for this procedure?

I can't put in the names of the sheets coz they change
frequently except for the sheet "Acc".

Thanks.
noel
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,173
Default macro to select sheets

Noel

The code below should work

Sub SelectToAcc()
Dim x As Long
Dim sShtName As String
Dim vGrpSht() As String
x = 1
ReDim vGrpSht(ThisWorkbook.Worksheets.Count)
Do While sShtName < "Acc"
If x ThisWorkbook.Worksheets.Count Then Exit Sub
sShtName = ThisWorkbook.Worksheets(x).Name
vGrpSht(x) = sShtName
x = x + 1
Loop
ReDim Preserve vGrpSht(x - 1)
ThisWorkbook.Worksheets(vGrpSht()).Select
End Sub


--
HTH
Nick Hodge
Microsoft MVP - Excel
Southampton, England
HIS


"noel" wrote in message
...
Hi,

I need to select an array of sheets, starting from the
first sheet to a sheet before the sheet "Acc". What is
the code for this procedure?

I can't put in the names of the sheets coz they change
frequently except for the sheet "Acc".

Thanks.
noel



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 4
Default macro to select sheets

Hi,

but the macro cannot run properly. It stops at the
line "ThisWorkbook.Worksheets(vGrpSht()).Select".

what i wanted to do was to change the fonts for "a2:c2"
to red and print and change it back to black again. So I
added the following to your code:

ActiveSheets.Range("a2:c2").Select
Selection.Font.ColorIndex = 3
ThisWorkbook.PrintOut
Range("a2:c2").Select
Selection.Font.ColorIndex = 2
Range("M35").Select

It doesn't work. But even if I do not add the above, the
code you gave me also stops at that last line. Why is
this so? Sorry, I'm very new to VBA macros.

Regards,
Val

-----Original Message-----
Noel

The code below should work

Sub SelectToAcc()
Dim x As Long
Dim sShtName As String
Dim vGrpSht() As String
x = 1
ReDim vGrpSht(ThisWorkbook.Worksheets.Count)
Do While sShtName < "Acc"
If x ThisWorkbook.Worksheets.Count Then Exit Sub
sShtName = ThisWorkbook.Worksheets(x).Name
vGrpSht(x) = sShtName
x = x + 1
Loop
ReDim Preserve vGrpSht(x - 1)
ThisWorkbook.Worksheets(vGrpSht()).Select
End Sub


--
HTH
Nick Hodge
Microsoft MVP - Excel
Southampton, England



"noel" wrote in

message
...
Hi,

I need to select an array of sheets, starting from the
first sheet to a sheet before the sheet "Acc". What is
the code for this procedure?

I can't put in the names of the sheets coz they change
frequently except for the sheet "Acc".

Thanks.
noel



.

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,173
Default macro to select sheets

Noel

I am off on holiday tomorrow, but it all worked ok for me. Can you post
back with the error you get and someone will diagnose that issue I'm sure?

It may also help to know your 'end game' so that someone may give you a
better route

--
HTH
Nick Hodge
Microsoft MVP - Excel
Southampton, England
HIS


"Noel" wrote in message
...
Hi,

but the macro cannot run properly. It stops at the
line "ThisWorkbook.Worksheets(vGrpSht()).Select".

what i wanted to do was to change the fonts for "a2:c2"
to red and print and change it back to black again. So I
added the following to your code:

ActiveSheets.Range("a2:c2").Select
Selection.Font.ColorIndex = 3
ThisWorkbook.PrintOut
Range("a2:c2").Select
Selection.Font.ColorIndex = 2
Range("M35").Select

It doesn't work. But even if I do not add the above, the
code you gave me also stops at that last line. Why is
this so? Sorry, I'm very new to VBA macros.

Regards,
Val

-----Original Message-----
Noel

The code below should work

Sub SelectToAcc()
Dim x As Long
Dim sShtName As String
Dim vGrpSht() As String
x = 1
ReDim vGrpSht(ThisWorkbook.Worksheets.Count)
Do While sShtName < "Acc"
If x ThisWorkbook.Worksheets.Count Then Exit Sub
sShtName = ThisWorkbook.Worksheets(x).Name
vGrpSht(x) = sShtName
x = x + 1
Loop
ReDim Preserve vGrpSht(x - 1)
ThisWorkbook.Worksheets(vGrpSht()).Select
End Sub


--
HTH
Nick Hodge
Microsoft MVP - Excel
Southampton, England



"noel" wrote in

message
...
Hi,

I need to select an array of sheets, starting from the
first sheet to a sheet before the sheet "Acc". What is
the code for this procedure?

I can't put in the names of the sheets coz they change
frequently except for the sheet "Acc".

Thanks.
noel



.



  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,173
Default macro to select sheets

Noel

Just came to me...At the top of the code, outside of the procedure (macro)
itself type 'Option Base 1' (No quotes)

Sorry my fault. I hate using zero based arrays

I don't think the route you are taking will work however as the print action
seems to deselect the sheets, at least in my small test, you are probably
better to cycle through the sheets

Can someone pick this up for me as cab is outside with meter running! Sorry

--
HTH
Nick Hodge
Microsoft MVP - Excel
Southampton, England
HIS


"Nick Hodge" wrote in message
...
Noel

I am off on holiday tomorrow, but it all worked ok for me. Can you post
back with the error you get and someone will diagnose that issue I'm sure?

It may also help to know your 'end game' so that someone may give you a
better route

--
HTH
Nick Hodge
Microsoft MVP - Excel
Southampton, England
HIS


"Noel" wrote in message
...
Hi,

but the macro cannot run properly. It stops at the
line "ThisWorkbook.Worksheets(vGrpSht()).Select".

what i wanted to do was to change the fonts for "a2:c2"
to red and print and change it back to black again. So I
added the following to your code:

ActiveSheets.Range("a2:c2").Select
Selection.Font.ColorIndex = 3
ThisWorkbook.PrintOut
Range("a2:c2").Select
Selection.Font.ColorIndex = 2
Range("M35").Select

It doesn't work. But even if I do not add the above, the
code you gave me also stops at that last line. Why is
this so? Sorry, I'm very new to VBA macros.

Regards,
Val

-----Original Message-----
Noel

The code below should work

Sub SelectToAcc()
Dim x As Long
Dim sShtName As String
Dim vGrpSht() As String
x = 1
ReDim vGrpSht(ThisWorkbook.Worksheets.Count)
Do While sShtName < "Acc"
If x ThisWorkbook.Worksheets.Count Then Exit Sub
sShtName = ThisWorkbook.Worksheets(x).Name
vGrpSht(x) = sShtName
x = x + 1
Loop
ReDim Preserve vGrpSht(x - 1)
ThisWorkbook.Worksheets(vGrpSht()).Select
End Sub


--
HTH
Nick Hodge
Microsoft MVP - Excel
Southampton, England



"noel" wrote in

message
.. .
Hi,

I need to select an array of sheets, starting from the
first sheet to a sheet before the sheet "Acc". What is
the code for this procedure?

I can't put in the names of the sheets coz they change
frequently except for the sheet "Acc".

Thanks.
noel


.





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
Macro to select all sheets belvy123 Excel Discussion (Misc queries) 7 March 27th 08 09:43 PM
macro to select all sheets belvy123 Excel Discussion (Misc queries) 1 March 26th 08 04:23 PM
Macro to select and print sheets JoeP Excel Discussion (Misc queries) 3 April 19th 07 06:44 PM
Select Sheets via Array Macro Frank Excel Programming 3 July 28th 04 01:51 AM
macro to select sheets/page in a workbook and print them Todd Excel Programming 1 June 8th 04 04:19 AM


All times are GMT +1. The time now is 12:27 AM.

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"