Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
TAM TAM is offline
external usenet poster
 
Posts: 10
Default Array Problem

Can you please tell me if it is possible to return a value of say the second
cell (B1) from the following statement...

Dim data As Variant

data = Range("A1:E1").Value

I have tried numerous ways but can not get the value of each cell in the
range which I need to examine before actioning

Thanks

TAM


  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,272
Default Array Problem


data = Range("A1:E1").Cells(1,2).Value

or just

data = Range("B1").Value


--

HTH

RP
(remove nothere from the email address if mailing direct)


"TAM" wrote in message
. uk...
Can you please tell me if it is possible to return a value of say the

second
cell (B1) from the following statement...

Dim data As Variant

data = Range("A1:E1").Value

I have tried numerous ways but can not get the value of each cell in the
range which I need to examine before actioning

Thanks

TAM




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

If you have to examine each cell

for example, lets test each cell to see if it can be treated as if it has a
number (blanks would be treated a zero and that would be OK for the
example).

dim bNotOk as Boolean
bNotOK = False
for each cell in Range("A1:E1")
if not isnumeric(cell) then
bNotOk = True
exit for
end if
Next
if bNotOk then
msgbox "Bad Data, quitting"
exit sub
End if

--
Regards,
Tom Ogilvy

"TAM" wrote in message
. uk...
Can you please tell me if it is possible to return a value of say the

second
cell (B1) from the following statement...

Dim data As Variant

data = Range("A1:E1").Value

I have tried numerous ways but can not get the value of each cell in the
range which I need to examine before actioning

Thanks

TAM




  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 783
Default Array Problem

TAM wrote:
Can you please tell me if it is possible to return a value of say the second
cell (B1) from the following statement...

Dim data As Variant

data = Range("A1:E1").Value

I have tried numerous ways but can not get the value of each cell in the
range which I need to examine before actioning

Thanks

TAM


Not exactly sure what your needs are, but after

Set rng = Range("A1:E1")

then

dataN = rng(N).Value will return for dataN the value from the Nth cell;
i.e.,

data1 = rng(1).Value will assign the value of A1 to data1;
data2 = rng(2).Value will assign the value of B1 to data2: etc.

Alan Beban
  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Array Problem

look, you dim 'data' as variant, then you try to give it value..i believe
you'd try:

redim data(1 to 5)

before you assign value..otherwise vba will show 'out of range' erro.

another error is, unless you dim data as range, i believe you need to loop
thorugh each data(i) to assign value. for example:

redim data(1 to 5)
for i = 1 to ubound(data)
xxxx
next

or dim data as range
set data = your range

rgds,

"TAM" wrote in message
. uk...
Can you please tell me if it is possible to return a value of say the
second
cell (B1) from the following statement...

Dim data As Variant

data = Range("A1:E1").Value

I have tried numerous ways but can not get the value of each cell in the
range which I need to examine before actioning

Thanks

TAM






  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 783
Default Array Problem

Dim data As Variant
data = Range("A1:E1").Value

assigns to the variant variable "data" the array of values from A1:E1.

data(1,2) would then return the value that's in B1.

sbcglobal seems not to have tested the advice given.

Alan Beban

sbcglobal wrote:
look, you dim 'data' as variant, then you try to give it value..i believe
you'd try:

redim data(1 to 5)

before you assign value..otherwise vba will show 'out of range' erro.

another error is, unless you dim data as range, i believe you need to loop
thorugh each data(i) to assign value. for example:

redim data(1 to 5)
for i = 1 to ubound(data)
xxxx
next

or dim data as range
set data = your range

rgds,

"TAM" wrote in message
. uk...

Can you please tell me if it is possible to return a value of say the
second
cell (B1) from the following statement...

Dim data As Variant

data = Range("A1:E1").Value

I have tried numerous ways but can not get the value of each cell in the
range which I need to examine before actioning

Thanks

TAM





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
Array Problem Scott Excel Discussion (Misc queries) 4 May 9th 06 05:22 PM
Array problem Bruce Excel Programming 1 December 8th 04 07:55 AM
Array Problem?? Michael Vaughan Excel Programming 6 November 12th 04 02:38 AM
Array Problem Phil Hageman[_3_] Excel Programming 0 November 19th 03 07:34 PM
Array Problem, Help Please. Bubu Excel Programming 9 November 18th 03 04:29 PM


All times are GMT +1. The time now is 11:24 AM.

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"