array and range

ericlch16

Active Member
Joined
Nov 2, 2007
Messages
311
Office Version
  1. 2016
  2. 2013
Platform
  1. Windows
Hi

I have a range which is several rows but 1 column
i.e rng = (.cells(x,1),cells(z,1))

I have an array
Dim myarray() as variant

Myarray = rng

When z>x i.e the range contains more than 1 value, it is fine
When z=x i.e the range contains only 1 value, it returns an error.

if range value is 8888 only, it returns error
if range value is 8888,9999,7777 it is ok
if range value is 8888, <empty space> it is ok (as empty space is considered as a value)

is there any reason the array has to take more than 1 value ? Any workaround for that?

Thanks
 

Excel Facts

Which Excel functions can ignore hidden rows?
The SUBTOTAL and AGGREGATE functions ignore hidden rows. AGGREGATE can also exclude error cells and more.
Hi,
try this update to your code & see if resolves your issue

VBA Code:
Dim myarray As Variant

myarray = Rng.Value
If Not IsArray(myarray) Then myarray = Array(myarray)

'rest of code

Dave
 
Upvote 0
Hi,
try this update to your code & see if resolves your issue

VBA Code:
Dim myarray As Variant

myarray = Rng.Value
If Not IsArray(myarray) Then myarray = Array(myarray)

'rest of code

Dave

VBA will give an error msg at

myarray = Rng.Value

if rng is only 1 value
 
Upvote 0

Forum statistics

Threads
1,214,631
Messages
6,120,645
Members
448,974
Latest member
DumbFinanceBro

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top