Return middle column of data using array

confusion123

Active Member
Joined
Jul 27, 2014
Messages
400
I have 3 columns of data.

Code:
MyArray() = Cells(1,1)

would return all three columns.

but I only want the middle column.

Is there a quick way of doing that, instead of creating another array and looping?

Thanks

EDIT SORTED:

Code:
Application.WorksheetFunction.Index(Myarray, 0, 2)
 
Last edited:

Some videos you may like

Excel Facts

Move date out one month or year
Use =EDATE(A2,1) for one month later. Use EDATE(A2,12) for one year later.

S_Wish

Board Regular
Joined
Jan 4, 2017
Messages
216
Hi,
Did I correclty understand, that you have in cells(1,1) something like "afdsa(separator)hgfds(separator)fdafds"
if yes, what the separator is?
 

confusion123

Active Member
Joined
Jul 27, 2014
Messages
400
I have data, say in columns 1 to 3 and I just want to retrieve the values in column 2.

Code:
Dim MyArray() As Variant

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

Dim MiddleArray() As Variant

MiddleArray = Application.WorksheetFunction.Index(MyArray, 0, 2)
 

S_Wish

Board Regular
Joined
Jan 4, 2017
Messages
216
As i don`t know what exactly is your data. I`d guess, that you need:
1. read file
2. take 2 column from it
3. place it in column B.

the second item can be done in such way:
if you have a symbol CR (carriage return), then just read it line by line.
in each line you have some separator between columns (i guess it is space). read from 1 space to 2 space in each line.
if you get more detailes I could help you with VBA macro

Sergej.

OR
use text to col, get 2 col.
 
Last edited:

Watch MrExcel Video

Forum statistics

Threads
1,123,470
Messages
5,601,840
Members
414,479
Latest member
Beau the dog

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