LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 4
Default Need to print different sheets conditionaly

Hi,

I need to print sheets on a condition of their content
I created a variable:

Dim parThreePrint As Variant

that returns a string of needed sheet names in a format:

"ad", "af", "ah", "ak", "al", "am", "ae", "aj"

and I inserted it ino a following procedure ( Macro Recorder have
recorded it for me)

Sheets(Array(parThreePrint)).Select

Error: Subscript out of range, pops up

if I copy the string from the edit box to the script it works perfect!!!

How to circumvent the problem???

P.S. I do not know how include " in a string so I have inserted their
names in quotation markson on every Sheet in cells(2,1)

So on Sheets("ab")
Cells(2,1) = "ab" ETC

Below I am attaching whole sub for reference


Sub Test()
'
' Test Macro
' Macro recorded 8/15/2004 by GK
'
' Keyboard Shortcut: Ctrl+Shift+T
'
' Sheets(Array("Sheet1", "Sheet2", "Sheet3")).Select
' Sheets("Sheet1").Activate

Dim arrTabs(1 To 12) As String

Dim parOnePage As String
Dim parTwoPage As String
Dim parThreePage As String

Dim parOnePrint As Variant
Dim parTwoPrint As Variant
Dim parThreePrint As Variant

Dim parTabStep As Byte

parOnePage = ""
parTwoPage = ""
parThreePage = ""

parOnePrint = ""
parTwoPrint = ""
parThreePrint = ""

parTabStep = 1



arrTabs(1) = "ab"
arrTabs(2) = "ac"
arrTabs(3) = "ad"
arrTabs(4) = "ae"
arrTabs(5) = "af"
arrTabs(6) = "ag"
arrTabs(7) = "ah"
arrTabs(8) = "aI"
arrTabs(9) = "aj"
arrTabs(10) = "ak"
arrTabs(11) = "al"
arrTabs(12) = "am"

For parTabStep = 1 To 12

Sheets(arrTabs(parTabStep)).Select


If Cells(1, 1) = 3 Then

parThreePage = parThreePage & ", " & Cells(2, 1)

ElseIf Cells(1, 1) = 2 Then

parTwoPage = parTwoPage & ", " & Cells(2, 1)

ElseIf Cells(1, 1) = 1 Then

parOnePage = parOnePage & ", " & Cells(2, 1)

End If


Next

parOnePrint = Right(parOnePage & parTwoPage & parThreePage,
Len(parOnePage & parTwoPage & parThreePage) - 2)
parTwoPrint = Right(parTwoPage & parThreePage, Len(parTwoPage &
parThreePage) - 2)

parThreePrint = Right(parThreePage, Len(parThreePage) - 2)


Sheets(arrTabs(1)).Select

Cells(3, 1) = parOnePrint
Cells(4, 1) = parTwoPrint
Cells(5, 1) = parThreePrint

Sheets(Array(parThreePrint)).Select
Sheets("ab").Activate


End Sub


 
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
Scan directory and import file conditionaly Michael.Tarnowski Excel Worksheet Functions 3 March 30th 09 02:00 PM
How do I print sheets in Excel without blank sheets after page Peggy New Users to Excel 2 January 12th 08 11:10 AM
Is it possible to conditionaly format based on the data label? David Charts and Charting in Excel 3 June 22nd 06 04:50 PM
add cells conditionaly not in continuous row or column loganinc6 Excel Discussion (Misc queries) 3 November 11th 05 03:32 AM
Formating a cell conditionaly DB Excel Worksheet Functions 1 October 14th 05 08:45 PM


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