Return array to sheet

tiredofit

Well-known Member
Joined
Apr 11, 2013
Messages
1,834
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

Can you sort left to right?
To sort left-to-right, use the Sort dialog box. Click Options. Choose "Sort left to right"
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,215,155
Messages
6,123,332
Members
449,098
Latest member
thnirmitha

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