2

I have a few fairly long currency lists in excel which I need to convert into an array format, for use in a different program. Are there any built-in formula that will return the string values of a list, into a string array?

For example the following:

a
b
c
d
e

Will return as "a","b","c","d","e" (even if it's just in the formula bar so I can copy and paste!)

I would prefer not to use VBA if possible simply due to time constraints, however if that works out relatively easy, any suggestions on that would be really helpful too.

Many thanks in advance

1

4 Answers 4

2

Nothing built in directly AFAIK.

Add a VBA module, paste:

Public Function ToArrStr(r As Range) As String
    ToArrStr = """" & Join(Application.Transpose(r), """,""") & """"
End Function

Then in the sheet you can: =ToArrStr(A1:A5)

(Assumes your passing > 1 cell vertically)

Sign up to request clarification or add additional context in comments.

1 Comment

This is spot on and will literally save me hours!!
2

The way I've seen this being handled in purely Excel formula is accumulating line by line:

A    B
---  -----------------
a    =""""&A1&""""
b    =B1&","""&A2&""""
c    =B2&","""&A3&""""
d    =B3&","""&A4&""""

Comments

2

FWIW, If you have the most recent upgrade to Excel, or are using the online app, then there is a built in formula. It is TEXTJOIN(). So:

="""" & TEXTJOIN(""",""",TRUE,A1:A5) & """"

enter image description here

Comments

0

Another way to convert list into array. Hope it helps.

Public Function ToArrStr1(r As Range) As String
Dim out As String
For i = 1 To r.Cells.Count
    If out = "" Then out = """" & r.Cells(i) & """" Else out = out & ",""" & r.Cells(i) & """"
Next i
ToArrStr1 = out
End Function

Then in the sheet you can: =ToArrStr1(A1:A5)

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.