VBA- Error

  • Thread starter Thread starter dipsy
  • Start date Start date
D

dipsy

Hi: I get "Subscript out of Range Error when I run this
code - any help is appreciated. Thanks in advance.

Dim CapSheetName(2) As String
CapSheetName(0) = "Capitalized Expenditures_Hrs"
CapSheetName(1) = "Capitalized Expenditures_%"

For Each CapName In CapSheetName
If sheets(CapName).Visible = True Then
sheets(CapName).Activate
ActiveSheet.Visible = False
End If
Next
 
Dipsy,

The loop is going around three times, for array items 0, 1, and 2. On 2, it
fails trying to find a sheet name of "". Change your array to

Dim CapSheetName(1) As String
 
Dipsy,

I meant to add that you can use F8 to step through a loop to see what it's
doing when working on a problem like this. Or put a breakpoint in it (F9),
then step it with F5 for one stop per loop.
 
Thanks.
-----Original Message-----
Dipsy,

I meant to add that you can use F8 to step through a loop to see what it's
doing when working on a problem like this. Or put a breakpoint in it (F9),
then step it with F5 for one stop per loop.

--
Earl Kiosterud
mvpearl omitthisword at verizon period net
-------------------------------------------

0, 1, and 2. On 2,
it


.
 
Back
Top