Array Problem
From: Jim L (anonymous_at_discussions.microsoft.com)
Date: 03/22/04
- Next message: TyeJae: "Re: Having trouble"
- Previous message: scottnshelly: "Re: "Find" Macro"
- Next in thread: Steve Garman: "Re: Array Problem"
- Reply: Steve Garman: "Re: Array Problem"
- Reply: Brad Vontur: "RE: Array Problem"
- Reply: Alan Beban: "Re: Array Problem"
- Messages sorted by: [ date ] [ thread ]
Date: Mon, 22 Mar 2004 13:25:59 -0800
When you define an array as Dim Array() as Variant, you
simply set up a placeholder for a future array.
How do you get excel to recognized that fact. I've got a a
routine that needs to recognized that if the array has not
been filled or ReDim'ed, it needs to exit the sub.
Unfortunately, I can't seem to find the right function to
do this. IsEmpty and IsNull do not work.
Sample code is below. What I'm doing is sending the
location of page breaks to an array and applying those
page breaks elsewhere.
The relavent code is as follows:
Sub Code1
'Main routine
Dim ArrayPB() as Variant
Call Code2(ArrayPB())
Call Code3(ArrayPB)
end sub
Sub Code2(ArrayPB2 as variant)
'routine which captures page breaks
If ActiveSheet.HPageBreaks.Count = 0 Then Exit Sub
ReDim ArrayPB2(ActiveSheet.HPageBreaks.Count) as Variant
x = 1
For each pb in ActiveSheet.HPageBreaks
ArrayPB2(x) = pb.Location.Address
x = x + 1
Next PB
End Sub
Sub Code3(ArrayPB3 as variant)
'rountine which applies page breaks
For X = 1 to ubound(ArrayPB3)
ActiveSheet.Rows(Right(ArrayPB3(x),len(ArrayPB3(x))_
- InStr(2,ArrayPB3(x),"$"))-1).PageBreak =_
xlPageBreakManual
Next x
end sub
The macros crashed on sheets with no defined pagebreaks;
hence, I added the Exit Sub statement. This generates a
subscript out of range error when the routine reaches
the "ActiveSheet.Rows" statement in Code3.
I'm looking for a solution where I could but something
simple such as "If IsEmpty(ArrayPB3) then exit sub" before
the For statement in Code3.
Thanks.
Jim.
- Next message: TyeJae: "Re: Having trouble"
- Previous message: scottnshelly: "Re: "Find" Macro"
- Next in thread: Steve Garman: "Re: Array Problem"
- Reply: Steve Garman: "Re: Array Problem"
- Reply: Brad Vontur: "RE: Array Problem"
- Reply: Alan Beban: "Re: Array Problem"
- Messages sorted by: [ date ] [ thread ]
Relevant Pages
|