How can I select a range and store into an array?

JOSHSKORN

New Member
Joined
Aug 22, 2022
Messages
16
Office Version
  1. 2019
Platform
  1. Windows
This topic will piggyback off of another thread that I "technically" think is answered, but the project isn't finished.

I have a list that I copy from Notepad in cell A6. I want the contents that I paste to go to an array. I'm lost, everything I've tried keeps getting type mismatches. I actually don't remember everything I've tried. Anyways, the list goes from A6 until it ends, (downward) it varies.

THIS code will select the range I need. As far as storing it into an array, I'm not sure how to do this.
VBA Code:
Range("A6", Range("A6").End(xlDown)).Select

My other thread: here.
 

Excel Facts

Spell Check in Excel
Press F7 to start spell check in Excel. Be careful, by default, Excel does not check Capitalized Werds (whoops)
It depend on just what form you want the array to take, but here is one way (assumes at least two values in A6 and down)

VBA Code:
Sub TestArray()
  Dim myArray As Variant
  
  myArray = Range("A6", Range("A6").End(xlDown)).Value
End Sub
 
Upvote 0
It depend on just what form you want the array to take, but here is one way (assumes at least two values in A6 and down)

VBA Code:
Sub TestArray()
  Dim myArray As Variant
 
  myArray = Range("A6", Range("A6").End(xlDown)).Value
End Sub

Thanks for the fast reply, but how do I check this? I was thinking showing the contents in a message box all together but I'm getting an error. I've tried this:
MsgBox myArray - Error: Type mismatch

and I've also tried this:
MsgBox Join(myArray, vbCrLf) - Error: Invalid procedure call or argument
 
Upvote 0
My sample code above reads the data in col A into a 2-dimensional array. To check those values, try this
VBA Code:
Sub TestArray_v2()
  Dim myArray As Variant
  
  myArray = Range("A6", Range("A6").End(xlDown)).Value
  MsgBox Join(Application.Transpose(myArray), vbCrLf)
End Sub

However, other circumstances (eg a 1-dimensional array, or a 'horizontal' rather than 'vertical' 2-D array) might require something different. It comes back to my earlier comment ..
It depend on just what form you want the array to take,
 
Upvote 0
My sample code above reads the data in col A into a 2-dimensional array. To check those values, try this
VBA Code:
Sub TestArray_v2()
  Dim myArray As Variant
 
  myArray = Range("A6", Range("A6").End(xlDown)).Value
  MsgBox Join(Application.Transpose(myArray), vbCrLf)
End Sub

However, other circumstances (eg a 1-dimensional array, or a 'horizontal' rather than 'vertical' 2-D array) might require something different. It comes back to my earlier comment ..
Thank you for your response. I apologize though, visually, it's what I'm looking for, but this won't do.

If you look at my other thread, I explain my project. Basically, I'm taking a setlist from a band's performance, then pasting the setlist into this list, starting at cell A6 on downward until it ends. I'll then be selecting the artist's name in cell B3, and cell range B6 on down as far as the list in column A goes, I'll be looking for the location of a tracklist, the location will be the name of the album. Folder structure is like this:
C:\Music\ArtistName\AlbumName\ListofTracksOnAlbum

So, paste the tracklist, change the contents of B3 (artist name), then the corresponding albums are listed next to the song tracks.

Where the problem may lie on your response, is, I'm not sure if this solution will let you loop through as you go, then build a string for output.
 
Upvote 0
Sorry, I don't understand what you require. The other thread does not mean much to me and clearly I don't have your folder structure or files to test with.
Here you seemed to be asking how to get values from A6 down and store them into an array. My code does that.
 
Upvote 0

Forum statistics

Threads
1,223,886
Messages
6,175,195
Members
452,616
Latest member
intern444

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