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

Hello

I have some problems dealing with the arrays.
Here the code

ThisRange = Range("A2:N81")
It supposed to be a array of 2 dimensions of type variant
So If I do uBound(ThisRange) I get 80 which seems to be right (80 rows).
But if I asked uBound(ThisRange(1)) which is supposed to give me the number
of elements coming from the columns I get an error 9 "Subscript out of range".

What is wrong in my code ?

Thanks
François
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,441
Default Working with range

Francois,

You are using the UBound function incorrectly:

ThisRange = Range("A2:N81")
MsgBox UBound(ThisRange, 1) 'returns 80
MsgBox UBound(ThisRange, 2) 'returns 14

ThisRange(1) is the first cell, cell A2.

ThisRange(1) is shorthand for ThisRange.Item(1)

HTH,
Bernie
MS Excel MVP


"François" wrote in message
...
Hello

I have some problems dealing with the arrays.
Here the code

ThisRange = Range("A2:N81")
It supposed to be a array of 2 dimensions of type variant
So If I do uBound(ThisRange) I get 80 which seems to be right (80 rows).
But if I asked uBound(ThisRange(1)) which is supposed to give me the

number
of elements coming from the columns I get an error 9 "Subscript out of

range".

What is wrong in my code ?

Thanks
François



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default Working with range

demo't from the immediate window:

ThisRange = Range("A2:N81").Value
? lbound(thisrange,1), ubound(thisrange,1)
1 80
? lbound(thisrange,2), ubound(thisrange,2)
1 14



--
Regards,
Tom Ogilvy

"François" wrote in message
...
Hello

I have some problems dealing with the arrays.
Here the code

ThisRange = Range("A2:N81")
It supposed to be a array of 2 dimensions of type variant
So If I do uBound(ThisRange) I get 80 which seems to be right (80 rows).
But if I asked uBound(ThisRange(1)) which is supposed to give me the

number
of elements coming from the columns I get an error 9 "Subscript out of

range".

What is wrong in my code ?

Thanks
François



  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default Working with range

Think you shifted from talking about Arrays to talking about ranges.

ThisRange(1) would raise an error since ThisRange is a two dimensional
array. And an array itself doesn't have any properties such as Item.

--
Regards,
Tom Ogilvy

"Bernie Deitrick" <deitbe @ consumer dot org wrote in message
...
Francois,

You are using the UBound function incorrectly:

ThisRange = Range("A2:N81")
MsgBox UBound(ThisRange, 1) 'returns 80
MsgBox UBound(ThisRange, 2) 'returns 14

ThisRange(1) is the first cell, cell A2.

ThisRange(1) is shorthand for ThisRange.Item(1)

HTH,
Bernie
MS Excel MVP


"François" wrote in message
...
Hello

I have some problems dealing with the arrays.
Here the code

ThisRange = Range("A2:N81")
It supposed to be a array of 2 dimensions of type variant
So If I do uBound(ThisRange) I get 80 which seems to be right (80 rows).
But if I asked uBound(ThisRange(1)) which is supposed to give me the

number
of elements coming from the columns I get an error 9 "Subscript out of

range".

What is wrong in my code ?

Thanks
François





  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 40
Default Working with range

Thanks Tom.
The purpose of using a range rather than using a logic like
activecell.(offset(0,1)) etc was to save some process time. Purpose is to
retrieve the colors of each cell of a range ("a2:n81") stored in one
worksheet and to copy some cells to another worksheet.
But I can not do :
Dim ThisRange as Range
ThisRange = Range("A2:N81") cause this is giving a runtime error.
Why ?

Thanks.


"Tom Ogilvy" wrote:

demo't from the immediate window:

ThisRange = Range("A2:N81").Value
? lbound(thisrange,1), ubound(thisrange,1)
1 80
? lbound(thisrange,2), ubound(thisrange,2)
1 14



--
Regards,
Tom Ogilvy

"François" wrote in message
...
Hello

I have some problems dealing with the arrays.
Here the code

ThisRange = Range("A2:N81")
It supposed to be a array of 2 dimensions of type variant
So If I do uBound(ThisRange) I get 80 which seems to be right (80 rows).
But if I asked uBound(ThisRange(1)) which is supposed to give me the

number
of elements coming from the columns I get an error 9 "Subscript out of

range".

What is wrong in my code ?

Thanks
François






  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 783
Default Working with range

Exactly what is it that is "giving . . . a runtime error"?

In any event, try Set ThisRange = Range("A2:N81")

Alan Beban

François wrote:
Thanks Tom.
The purpose of using a range rather than using a logic like
activecell.(offset(0,1)) etc was to save some process time. Purpose is to
retrieve the colors of each cell of a range ("a2:n81") stored in one
worksheet and to copy some cells to another worksheet.
But I can not do :
Dim ThisRange as Range
ThisRange = Range("A2:N81") cause this is giving a runtime error.
Why ?

Thanks.


"Tom Ogilvy" wrote:


demo't from the immediate window:

ThisRange = Range("A2:N81").Value
? lbound(thisrange,1), ubound(thisrange,1)
1 80
? lbound(thisrange,2), ubound(thisrange,2)
1 14



--
Regards,
Tom Ogilvy

"François" wrote in message
...

Hello

I have some problems dealing with the arrays.
Here the code

ThisRange = Range("A2:N81")
It supposed to be a array of 2 dimensions of type variant
So If I do uBound(ThisRange) I get 80 which seems to be right (80 rows).
But if I asked uBound(ThisRange(1)) which is supposed to give me the


number

of elements coming from the columns I get an error 9 "Subscript out of


range".

What is wrong in my code ?

Thanks
François




  #7   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default Working with range

You introduced the term Array and the code you posted did result in an array
being stored in the variant variable Thisrange and you use ubound which is a
function that operates on arrays. So my answer was for an array question.

If you are trying to retrieve colors from cells, then you don't need an
array. Alan showed you the correction

Dim ThisRange as Range
set ThisRange = Range("A2:N81")
msgbox thisrange.Address

if you want the number of rows and columns

msgbox thisrange.rows.count
msgbox thisrange.columns.count

if you want to refer to B3

msgbox thisrange.offset(1,1).Address



--
Regards,
Tom Ogilvy

"François" wrote in message
...
Thanks Tom.
The purpose of using a range rather than using a logic like
activecell.(offset(0,1)) etc was to save some process time. Purpose is to
retrieve the colors of each cell of a range ("a2:n81") stored in one
worksheet and to copy some cells to another worksheet.
But I can not do :
Dim ThisRange as Range
ThisRange = Range("A2:N81") cause this is giving a runtime error.
Why ?

Thanks.


"Tom Ogilvy" wrote:

demo't from the immediate window:

ThisRange = Range("A2:N81").Value
? lbound(thisrange,1), ubound(thisrange,1)
1 80
? lbound(thisrange,2), ubound(thisrange,2)
1 14



--
Regards,
Tom Ogilvy

"François" wrote in message
...
Hello

I have some problems dealing with the arrays.
Here the code

ThisRange = Range("A2:N81")
It supposed to be a array of 2 dimensions of type variant
So If I do uBound(ThisRange) I get 80 which seems to be right (80

rows).
But if I asked uBound(ThisRange(1)) which is supposed to give me the

number
of elements coming from the columns I get an error 9 "Subscript out of

range".

What is wrong in my code ?

Thanks
François






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
Countif Range not working tommcbrny Excel Worksheet Functions 4 August 1st 08 05:29 PM
Working with the range object [email protected] Excel Discussion (Misc queries) 2 November 27th 07 09:05 AM
Working with a range Dan Chupinsky Excel Discussion (Misc queries) 3 July 6th 05 06:39 AM
setting a range not working, please help Dan Mullen Excel Programming 3 May 28th 04 10:31 AM
Range selection not working kanan Excel Programming 3 April 22nd 04 05:19 PM


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