Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11
Default Help on subscript out of range error (VB6/VBA)

Hi,

I want to work with multiple excel workbooks en worksheets using a
stand alone VB6 application.

1. First I open and close the workbooks and populate a listbox with
sheetnames.

2. Then I select some sheets and fill an Array. (This array contains
sheetnames from different workbooks)

3. The last step is to open and close the workbooks again and loop
(For Each) through the sheets to get the information I need using the
above mentioned array.

The only problem is that I receive an "Subscript out of Range" error.
This error occurs because I'm attempting tot access a worksheet that
doesn't exist in a particular workbook.

So I used "On error Resume next" and "On error Goto 0" trying to skip
the Sheet that doesn't exist in one workbook and go to the next sheet.
Unfortunately with no results sofar. (either is does nothing at all or
I receive the subscipt out of Range error )

Question:
1) Can anyone point me in the right direction ?

Help is appreciated.

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default Help on subscript out of range error (VB6/VBA)

Dim sh as Excel.worksheet

On Error Resume Next
set sh = xlApp.Workbooks(1).Worksheets(sName)
On Error goto 0
if not sh is nothing then
' sheet exists, work with it
myval = sh.Cells(1,1).Value
end if

--
Regards,
Tom Ogilvy

farmer wrote in message
...
Hi,

I want to work with multiple excel workbooks en worksheets using a
stand alone VB6 application.

1. First I open and close the workbooks and populate a listbox with
sheetnames.

2. Then I select some sheets and fill an Array. (This array contains
sheetnames from different workbooks)

3. The last step is to open and close the workbooks again and loop
(For Each) through the sheets to get the information I need using the
above mentioned array.

The only problem is that I receive an "Subscript out of Range" error.
This error occurs because I'm attempting tot access a worksheet that
doesn't exist in a particular workbook.

So I used "On error Resume next" and "On error Goto 0" trying to skip
the Sheet that doesn't exist in one workbook and go to the next sheet.
Unfortunately with no results sofar. (either is does nothing at all or
I receive the subscipt out of Range error )

Question:
1) Can anyone point me in the right direction ?

Help is appreciated.



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default Help on subscript out of range error (VB6/VBA)

A better solution might be to store which workbook has which worksheet names
and not try to access a workbook that doesn't have that worksheet name.

--
Regards,
Tom Ogilvy

farmer wrote in message
...
Hi,

I want to work with multiple excel workbooks en worksheets using a
stand alone VB6 application.

1. First I open and close the workbooks and populate a listbox with
sheetnames.

2. Then I select some sheets and fill an Array. (This array contains
sheetnames from different workbooks)

3. The last step is to open and close the workbooks again and loop
(For Each) through the sheets to get the information I need using the
above mentioned array.

The only problem is that I receive an "Subscript out of Range" error.
This error occurs because I'm attempting tot access a worksheet that
doesn't exist in a particular workbook.

So I used "On error Resume next" and "On error Goto 0" trying to skip
the Sheet that doesn't exist in one workbook and go to the next sheet.
Unfortunately with no results sofar. (either is does nothing at all or
I receive the subscipt out of Range error )

Question:
1) Can anyone point me in the right direction ?

Help is appreciated.



Reply
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
Error:Subscript out of range Jay Excel Discussion (Misc queries) 1 April 10th 08 10:25 PM
Subscript out of range error moglione1 Excel Discussion (Misc queries) 2 August 30th 05 01:21 PM
Subscript out of range error Chris M.[_3_] Excel Programming 1 August 27th 03 05:03 PM
Run time error '9' Subscript out of range Tina Excel Programming 1 August 25th 03 02:05 AM
Subscript out of range error Gary[_4_] Excel Programming 1 August 13th 03 07:20 AM


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