Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 72
Default Help with this code

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.
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35,218
Default Help with this code

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.

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.
"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
  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35,218
Default Help with this code

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)?



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.
"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
  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 227
Default Help with this code

Have you dimmed theRange? If not, is Option Explicit declared in this
code module?

  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Help with this code


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.
"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.

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


--
avveerkar
------------------------------------------------------------------------
avveerkar's Profile: http://www.excelforum.com/member.php...o&userid=30338
View this thread: http://www.excelforum.com/showthread...hreadid=503167



  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35,218
Default Help with this code

You can set a range on an inactive sheet--but you can't select that range.

avveerkar wrote:

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.
"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.

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

--
avveerkar
------------------------------------------------------------------------
avveerkar's Profile: http://www.excelforum.com/member.php...o&userid=30338
View this thread: http://www.excelforum.com/showthread...hreadid=503167


--

Dave Peterson
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
split post code (zip code) out of cell that includes full address Concord Excel Discussion (Misc queries) 4 October 15th 09 06:59 PM
Drop Down/List w/Code and Definition, only code entered when selec Spiritdancer Excel Worksheet Functions 2 November 2nd 07 03:57 AM
Generic protect/unprotect code through buttons and code? StargateFanFromWork[_3_] Excel Programming 4 December 31st 05 12:10 AM
stubborn Excel crash when editing code with code, one solution Brian Murphy Excel Programming 0 February 20th 05 05:56 AM
VBA code delete code but ask for password and unlock VBA protection WashoeJeff Excel Programming 0 January 27th 04 07:07 AM


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