array and range

ericlch16

Active Member
Joined
Nov 2, 2007
Messages
301
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

Excel Can Read to You
Customize Quick Access Toolbar. From All Commands, add Speak Cells or Speak Cells on Enter to QAT. Select cells. Press Speak Cells.

dmt32

Well-known Member
Joined
Jul 3, 2012
Messages
6,833
Office Version
  1. 2019
Platform
  1. Windows
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
 

ericlch16

Active Member
Joined
Nov 2, 2007
Messages
301
Office Version
  1. 2016
  2. 2013
Platform
  1. Windows
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
 

Forum statistics

Threads
1,143,677
Messages
5,720,249
Members
422,272
Latest member
ginkgoVil

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
Top