Return array to sheet

tiredofit

Well-known Member
Joined
Apr 11, 2013
Messages
1,926
Office Version
  1. 365
  2. 2019
Platform
  1. Windows
If I want to return the values of an array to the worksheet, I write:

Code:
Sheet1.Cells(1,1).Resize(10,20).Value = MyArray()

But what if my array is "not normal"?

My data is as follows:

Code:
Name1-LastName1
Name2-LastName2

I wrote the following to split it:

Code:
Dim DataArray() As Variant

DataArray() = Cells(1, 1).CurrentRegion.Value

For Counter = 1 To 2
    
    NameArray(Counter, 1) = Split(DataArray(Counter, 1), "-")
    
Next Counter

If I try:

Code:
Sheet2.Cells(1, 1).Resize(2,1).Value = NameArray()

it no longer works.

It's because NameArray looks like this in the Locals Window:

Code:
NameArray(1)
    NameArray(1,1)
        NameArray(1,1)(0)
        NameArray(2,1)(1)

How can I return the values of NameArray to the worksheet?

Thanks
 

Excel Facts

Test for Multiple Conditions in IF?
Use AND(test, test, test, test) or OR(test, test, test, ...) as the logical_test argument of IF.
If I want to return the values of an array to the worksheet, I write:

Code:
Sheet1.Cells(1,1).Resize(10,20).Value = MyArray()

But what if my array is "not normal"?

My data is as follows:

Code:
Name1-LastName1
Name2-LastName2

I wrote the following to split it:

Code:
Dim DataArray() As Variant

DataArray() = Cells(1, 1).CurrentRegion.Value

For Counter = 1 To 2
  
    NameArray(Counter, 1) = Split(DataArray(Counter, 1), "-")
  
Next Counter

If I try:

Code:
Sheet2.Cells(1, 1).Resize(2,1).Value = NameArray()

it no longer works.

It's because NameArray looks like this in the Locals Window:

Code:
NameArray(1)
    NameArray(1,1)
        NameArray(1,1)(0)
        NameArray(2,1)(1)

How can I return the values of NameArray to the worksheet?

Thanks
Must I loop to return the values?

Code:
For Counter = 1 To 2

    Sheet2.Cells(Counter, 1) = NameArray(Counter, 1)(0)
    Sheet2.Cells(Counter, 2) = NameArray(Counter, 1)(1)

Next Counter
 
Upvote 0

Forum statistics

Threads
1,224,823
Messages
6,181,181
Members
453,022
Latest member
Mohamed Magdi Tawfiq Emam

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