×
INTELLIGENT WORK FORUMS
FOR ENGINEERING PROFESSIONALS

Log In

Come Join Us!

Are you an
Engineering professional?
Join Eng-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!
  • Students Click Here

*Eng-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

Jobs

Automate Grouping of Sheets...

Automate Grouping of Sheets...

Automate Grouping of Sheets...

(OP)
I need to be able to print (via VBA on a custom tool button) all sheets in a workbook, EXCEPT the first 2 sheets.

I can make it count the total number of sheets and tried to use:

   Dim tabcount As Integer
   tabcount = ThisWorkbook.Worksheets.Count
   Worksheets(Array(2 - tabcount)).Select

Thinking that Array(2 - tabcount) would be 2 THRU tabcount... not so apparently.

Neither did Array(2 :: tabcount) or Array(2 : tabcount) work.

I'm stuck now.  Anyone know how to make it do what I want?
 

RE: Automate Grouping of Sheets...

2-tabcount is "2 minus tabcount"
2::tabcount means "2 (here is a new line of VBA code) tabcount"

You can't specify a range of values for the Array function.  You have to specify each value.  Array will not work for you.  You need something like

CODE

Dim Tabcount As Long
Dim myArray() As Variant
Tabcount = ThisWorkbook.Worksheets.Count
ReDim myArray(Tabcount - 3)
For i = 0 To UBound(myArray)
  myArray(i) = i + 3
Next i
Worksheets(myArray).Select

-handleman, CSWP (The new, easy test)

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Eng-Tips Forums free from inappropriate posts.
The Eng-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Eng-Tips forums is a member-only feature.

Click Here to join Eng-Tips and talk with other members!


Resources