Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
DiscussionsAccessExcelInfoPathOutlookPowerPointPublisherWord
DirectoryUser Groups
Related Topics
Outlook ExpressInternet ExplorerWindowsMS Server ProductsMore Topics ...

MS Office Forum / Excel / Programming / January 2006

Tip: Looking for answers? Try searching our database.

Help with this code

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
matelot - 20 Jan 2006 01:49 GMT
I must be blind. Please help me find what's the problem with this code.
I get the following error when I run it.
"Run-Time error 1004: Application-defined or object-defined error"
My code is really simple and yet I don't know what's wrong with it.

Dim myArray(1,1) as string
c= 1
set s = workbooks("test.xls").sheets(2)
Set theRange = s.Range(Cells(1, c), Cells(UBound(myArray), c)) <-run time
error on this line

Please help.
Dave Peterson - 20 Jan 2006 02:44 GMT
Cells() refers to the activesheet.  If S isn't the activesheet, then kablewie!!!

Set theRange = s.Range(Cells(1, c), Cells(UBound(myArray), c))
could be
Set theRange = s.Range(s.Cells(1, c), s.Cells(UBound(myArray), c))

or

with s
Set theRange = .Range(.Cells(1, c), .Cells(UBound(myArray), c))
end with

The dots mean that that thing belongs to the previous With object.

> I must be blind. Please help me find what's the problem with this code.
> I get the following error when I run it.
[quoted text clipped - 8 lines]
>
> Please help.

Signature

Dave Peterson

Dave Peterson - 20 Jan 2006 02:46 GMT
I'm betting that you did put something in that array.

And maybe...

with s
Set theRange = .Range(.Cells(1, c), .Cells(UBound(myArray,1), c))
end with

Did you really mean to use myArray(1,1)?

> I must be blind. Please help me find what's the problem with this code.
> I get the following error when I run it.
[quoted text clipped - 8 lines]
>
> Please help.

Signature

Dave Peterson

Mark Lincoln - 20 Jan 2006 03:01 GMT
Have you dimmed theRange?  If not, is Option Explicit declared in this
code module?
avveerkar - 20 Jan 2006 03:27 GMT
matelot Wrote:
> I must be blind. Please help me find what's the problem with this code.
> I get the following error when I run it.
[quoted text clipped - 9 lines]
>
> Please help.
VBA will not permit you to set range on a sheet which is not active.
Perhaps you are on sheet1 ( sheet1 is active ) and then trying to set
range in sheet2.  Be on sheet2 ( sheet2 is active) and run the macro,
you will not get the error. You could have "s.activate" before your
"set theRange" statement.

A V Veerkar

Signature

avveerkar

Dave Peterson - 20 Jan 2006 17:47 GMT
You can set a range on an inactive sheet--but you can't select that range.

> matelot Wrote:
> > I must be blind. Please help me find what's the problem with this code.
[quoted text clipped - 23 lines]
> avveerkar's Profile: http://www.excelforum.com/member.php?action=getinfo&userid=30338
> View this thread: http://www.excelforum.com/showthread.php?threadid=503167

Signature

Dave Peterson

 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.