Home |
Search |
Today's Posts |
#1
Posted to microsoft.public.excel.programming
|
|||
|
|||
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 |
Display Modes | |
|
|
Similar Threads | ||||
Thread | Forum | |||
Scan directory and import file conditionaly | Excel Worksheet Functions | |||
How do I print sheets in Excel without blank sheets after page | New Users to Excel | |||
Is it possible to conditionaly format based on the data label? | Charts and Charting in Excel | |||
add cells conditionaly not in continuous row or column | Excel Discussion (Misc queries) | |||
Formating a cell conditionaly | Excel Worksheet Functions |