Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 37
Default Run-time error '9' on With statement

I wrote some code to sort through a huge dataset in one workbook, find a
particular piece of data and insert it into another workbook. The code is
contained in a module in the latter workbook. The code worked fine, but I
tried to adapt it to do something similar in another module and started
getting a run time error. So I tried executing the original code and I'm
getting the same error now with the original code. How could the code have
worked and now it doesn't if I didn't change anything? The line(s) of code in
question is:

With Workbooks("Workbook_Name").Sheets("Sheet_Name").Ra nge"Named_Range")
'<<THIS LINE IS WHERE I GET THE ERROR
Set rngVariable = .Find(what:=strVariable, LookIn:=xlValues)
End With

If I activate the workbook I'm looking in I think it will fix this problem,
but I wanted to avoid this because it will cause the code to switch back and
forth between workboks again and again (the code is imbedded in a loop). Any
insight into the cause/solution would be much appreciated!

Thanks in advance.
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Run-time error '9' on With statement


Hello Charlie,

Error 9 is "Subcript out of Range". Something I did notice in your code
which might be a typo is a mssing "(" after Range.

Posted...

With Workbooks("Workbook_Name").Sheets("Sheet_Name").Ra
nge"Named_Range")

Should be...

With Workbooks("Workbook_Name").Sheets("Sheet_Name").Ra
nge("Named_Range")

That would flag a different error if your code were typed this way. If
the Sheet isn't active when the code is run, you will get error 9. Also
check that your variables contain valid data.

Sincerely,
Leith Ross


--
Leith Ross
------------------------------------------------------------------------
Leith Ross's Profile: http://www.excelforum.com/member.php...o&userid=18465
View this thread: http://www.excelforum.com/showthread...hreadid=496442

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default Run-time error '9' on With statement

Try it this way
With Workbooks("Workbook_Name.xls").Range("Named_Range" ).RefersToRange
.find . . .

--
Regards,
Tom Ogilvy



"xlcharlie" wrote in message
...
I wrote some code to sort through a huge dataset in one workbook, find a
particular piece of data and insert it into another workbook. The code is
contained in a module in the latter workbook. The code worked fine, but I
tried to adapt it to do something similar in another module and started
getting a run time error. So I tried executing the original code and I'm
getting the same error now with the original code. How could the code

have
worked and now it doesn't if I didn't change anything? The line(s) of code

in
question is:

With

Workbooks("Workbook_Name").Sheets("Sheet_Name").Ra nge"Named_Range")
'<<THIS LINE IS WHERE I GET THE ERROR
Set rngVariable = .Find(what:=strVariable, LookIn:=xlValues)
End With

If I activate the workbook I'm looking in I think it will fix this

problem,
but I wanted to avoid this because it will cause the code to switch back

and
forth between workboks again and again (the code is imbedded in a loop).

Any
insight into the cause/solution would be much appreciated!

Thanks in advance.



  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 7,247
Default Run-time error '9' on With statement

With
Workbooks("Workbook_Name.xls").Range("Named_Range" ).RefersToRange


I think you meant

With
Workbooks("Workbook_Name.xls").Names("Named_Range" ).RefersToRange


--
Cordially,
Chip Pearson
Microsoft MVP - Excel
Pearson Software Consulting, LLC
www.cpearson.com


"Tom Ogilvy" wrote in message
...
Try it this way
With
Workbooks("Workbook_Name.xls").Range("Named_Range" ).RefersToRange
.find . . .

--
Regards,
Tom Ogilvy



"xlcharlie" wrote in
message
...
I wrote some code to sort through a huge dataset in one
workbook, find a
particular piece of data and insert it into another workbook.
The code is
contained in a module in the latter workbook. The code worked
fine, but I
tried to adapt it to do something similar in another module
and started
getting a run time error. So I tried executing the original
code and I'm
getting the same error now with the original code. How could
the code

have
worked and now it doesn't if I didn't change anything? The
line(s) of code

in
question is:

With

Workbooks("Workbook_Name").Sheets("Sheet_Name").Ra nge"Named_Range")
'<<THIS LINE IS WHERE I GET THE ERROR
Set rngVariable = .Find(what:=strVariable,
LookIn:=xlValues)
End With

If I activate the workbook I'm looking in I think it will fix
this

problem,
but I wanted to avoid this because it will cause the code to
switch back

and
forth between workboks again and again (the code is imbedded
in a loop).

Any
insight into the cause/solution would be much appreciated!

Thanks in advance.





  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default Run-time error '9' on With statement

yes, I was waiting for it to show up so I could post the correction.
Accidentally Hit the send key before I finished editing. Thanks.

--
Regards,
Tom Ogilvy



"Chip Pearson" wrote in message
...
With
Workbooks("Workbook_Name.xls").Range("Named_Range" ).RefersToRange


I think you meant

With
Workbooks("Workbook_Name.xls").Names("Named_Range" ).RefersToRange


--
Cordially,
Chip Pearson
Microsoft MVP - Excel
Pearson Software Consulting, LLC
www.cpearson.com


"Tom Ogilvy" wrote in message
...
Try it this way
With
Workbooks("Workbook_Name.xls").Range("Named_Range" ).RefersToRange
.find . . .

--
Regards,
Tom Ogilvy



"xlcharlie" wrote in
message
...
I wrote some code to sort through a huge dataset in one
workbook, find a
particular piece of data and insert it into another workbook.
The code is
contained in a module in the latter workbook. The code worked
fine, but I
tried to adapt it to do something similar in another module
and started
getting a run time error. So I tried executing the original
code and I'm
getting the same error now with the original code. How could
the code

have
worked and now it doesn't if I didn't change anything? The
line(s) of code

in
question is:

With

Workbooks("Workbook_Name").Sheets("Sheet_Name").Ra nge"Named_Range")
'<<THIS LINE IS WHERE I GET THE ERROR
Set rngVariable = .Find(what:=strVariable,
LookIn:=xlValues)
End With

If I activate the workbook I'm looking in I think it will fix
this

problem,
but I wanted to avoid this because it will cause the code to
switch back

and
forth between workboks again and again (the code is imbedded
in a loop).

Any
insight into the cause/solution would be much appreciated!

Thanks in advance.







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
If statement to compare time cell to a time Z-Man-Cek Excel Worksheet Functions 16 July 29th 16 08:17 AM
IF statement to calculate time usage in specific time bands Daren Excel Worksheet Functions 6 January 31st 07 01:34 PM
Path/File access error (Error 75) using Name Statement blayne Excel Programming 7 November 22nd 05 09:20 PM
Path/File access error (Error 75) after using Name Statement blayne Excel Programming 0 November 10th 05 12:33 AM
run-time error '1004': Application-defined or object-deifined error [email protected] Excel Programming 5 August 10th 05 09:39 PM


All times are GMT +1. The time now is 07:27 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"