Thread: ARRAYS
View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.programming
acw acw is offline
external usenet poster
 
Posts: 19
Default ARRAYS

Gary

Change the line
prange = Sheets("macroinputs").Range("O8").Value to
prange = evaluate("={" & Range("O8").Value & "}")

and the line
Sheets(Array(prange)).Select to
sheets(prange).select

I think there is a more elegant way to do this but not
sure what it is.

Tony

-----Original Message-----
Hi there,

Having a problem with the following code

Sub mcrPrint()
Dim prange As String

Sheets("macroinputs").Range("N1").Value = InputBox("Enter
Section No to print/preview or ALL", , "ALL")
Sheets("macroinputs").Range("N2").Value = InputBox("Print
(Y) or Preview (N)", , "N")
prange = Sheets("macroinputs").Range("O8").Value

If Sheets("macroinputs").Range("N1").Value < "All"
Then
Sheets(Array(prange)).Select
If Sheets("macroinputs").Range("N2").Value = "Y"
Then
ActiveWindow.SelectedSheets.PrintOut
Copies:=1, Collate:=True
Else
ActiveWindow.SelectedSheets.PrintPreview
End If
End If
End Sub

I get an error "Subscript out of range" run-time error 9

What I am trying to do is as follows:-
The excle file has over 100 sheets, some of which are
hidden. Sheets are broken down into 10 sections, but
there may only be 4 sheets in a given section that
require printing.

I use a table to list which sheets are hidden, or not.

To get the value for prange - as in the code, I use a
lookup on this table.

The data in prange is currently
"CAT0", "00", "01", "06", "07", "08", "09"

as you can see, sheets "02", "03", "04", "05" are hidden,
and do not require printing.

When I replace prange in the vb code, with this value,
the macro works just fine.

What can I do ?

.