Join array VBA

Tian1

Board Regular
Joined
Jan 11, 2012
Messages
140
Good day,

I would just like to join the following array and display it in one string. I've got the following code which should be more or less in line with what I want to achieve. (this is just an outtake from the rest of my code)

Code:
ReDim accndata(accs, 1)


For acccount = 1 To accs


    accndata(acccount, 1) = Cells(rowbegin + 1, 3).Value
    rowbegin = rowbegin + 1
    
    ReDim Preserve accndata(accs, 1)
    total = accndata(acccount, 1) & vbCrLf
    
Next acccount


MsgBox "the values of my dynamic array are: " & vbCrLf & total

I appreciate the help!
 

Excel Facts

Quick Sum
Select a range of cells. The total appears in bottom right of Excel screen. Right-click total to add Max, Min, Count, Average.
I don't understand your dimensioning and re-dimensioning of the accndata array. However, from what I can make of your partial code, you are trying to read values from a column into an array & then join those values with vbCrLf ?

If so, you could try something like this that reads the values into the array all at once & then joins the array values in a single pass as well.

If this is not what you want, then please give more detail about what you have, where, and what you are trying to achieve.

With the dummy values I have used, this reads the values from C6:C9 into the array.

Rich (BB code):
Sub Join_Values()
  Dim accndata As Variant
  Dim accs As Long, rowbegin As Long
  Dim Total As String
  
  accs = 4
  rowbegin = 5
  accndata = Cells(rowbegin + 1, 3).Resize(accs).Value
  Total = Join(Application.Transpose(accndata), vbCrLf)
  MsgBox "the values of my dynamic array are: " & vbCrLf & Total
End Sub
 
Upvote 0

Forum statistics

Threads
1,226,364
Messages
6,190,537
Members
453,611
Latest member
JRM59

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