Turn a value range in a cell into a comma separated list

Redlaw

Is there a formula I can have in cell B1 that looks at A1 and creates a comma-based list?

So below, A1 is something I can type into. B1 is a formula. Is this possible? I will have A1 always follow the same format as a XXX-XXX range.

+-------+-----------+----------------------+
| TABLE | A (Input) |      B (Result)      |
+-------+-----------+----------------------+
|     1 | 1-10      | 1,2,3,4,5,6,7,8,9,10 |
+-------+-----------+----------------------+
Tim Williams

Put the code below in a regular VBA module then you can use (eg):

=NumRange(A1)

in B1

Function NumRange(v)
    Dim arr, x As Long, rv As String, sep As String
    If InStr(v, "-") Then
        arr = Split(v, "-")
        arr(0) = Trim(arr(0))
        arr(1) = Trim(arr(1))
        If IsNumeric(arr(0)) And IsNumeric(arr(1)) Then
            For x = CLng(arr(0)) To CLng(arr(1))
                rv = rv & sep & x
                sep = ","
            Next x
        End If
    End If
    NumRange = rv
End Function

EDIT - handle multiple ranges

Function NumRange(v)
    Dim arrC, arr, x As Long, rv As String, sep As String, e

    arrC = Split(v, ",")
    rv = ""

    For Each e In arrC
        If InStr(e, "-") Then
            arr = Split(e, "-")
            arr(0) = Trim(arr(0))
            arr(1) = Trim(arr(1))
            If IsNumeric(arr(0)) And IsNumeric(arr(1)) Then
                For x = CLng(arr(0)) To CLng(arr(1))
                    rv = rv & sep & x
                    sep = ","
                Next x
            End If
        ElseIf IsNumeric(e) Then
            rv = rv & sep & CLng(e)
            sep = ","
        End If
    Next e
    NumRange = rv
End Function

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Turn a value range in a cell into a comma separated list

From Dev

Turn properties of object into a comma-separated list?

From Dev

convert cell to a list of element separated by comma MATLAB

From Dev

Count items in comma separated list in single cell

From Dev

How to put a comma separated value to a numpy cell

From Dev

Check if value exists in a comma separated list

From Dev

Regular Expression for last value in comma separated list

From Dev

Splitting a column value into list of values separated by comma

From Dev

Find value in comma-separated list

From Dev

Find string value in comma-separated list

From Dev

is there a one cell formula for getting a comma separated list with increasing numbers in EXCEL

From Dev

Excel - pivot values in one cell (as comma-separated value)

From Dev

vlookup for comma separated cell value with refrence from another sheet

From Dev

Using Linq to find a value in comma separated value in a List

From Dev

Comma separated list in twig

From Dev

Comma separated values to List

From Dev

Mysql comma separated value

From Dev

Split comma separated string and compare each value in a List

From Dev

PostgreSQL get last value in a comma separated list of values

From Dev

Splitting List<T> based on comma separated property value using Linq

From Dev

How to create comma separated list of numbers based on numeric value in column

From Dev

PostgreSQL get last value in a comma separated list of values

From Dev

Transform matlab function output (cell array) into comma separated list without temporary cell array

From Dev

remove value(s) from a comma separated list from other value(s) from one other comma separated list

From Dev

Easy way to turn JavaScript array into comma AND Quotation Marks separated string list?

From Dev

Filter text from each file and turn it into a list of comma-separated values

From Dev

Turn comma-separated string into GetFiles SearchPattern

From Dev

Turn comma-separated string into GetFiles SearchPattern

From Dev

Turn a php array into comma separated array

Related Related

  1. 1

    Turn a value range in a cell into a comma separated list

  2. 2

    Turn properties of object into a comma-separated list?

  3. 3

    convert cell to a list of element separated by comma MATLAB

  4. 4

    Count items in comma separated list in single cell

  5. 5

    How to put a comma separated value to a numpy cell

  6. 6

    Check if value exists in a comma separated list

  7. 7

    Regular Expression for last value in comma separated list

  8. 8

    Splitting a column value into list of values separated by comma

  9. 9

    Find value in comma-separated list

  10. 10

    Find string value in comma-separated list

  11. 11

    is there a one cell formula for getting a comma separated list with increasing numbers in EXCEL

  12. 12

    Excel - pivot values in one cell (as comma-separated value)

  13. 13

    vlookup for comma separated cell value with refrence from another sheet

  14. 14

    Using Linq to find a value in comma separated value in a List

  15. 15

    Comma separated list in twig

  16. 16

    Comma separated values to List

  17. 17

    Mysql comma separated value

  18. 18

    Split comma separated string and compare each value in a List

  19. 19

    PostgreSQL get last value in a comma separated list of values

  20. 20

    Splitting List<T> based on comma separated property value using Linq

  21. 21

    How to create comma separated list of numbers based on numeric value in column

  22. 22

    PostgreSQL get last value in a comma separated list of values

  23. 23

    Transform matlab function output (cell array) into comma separated list without temporary cell array

  24. 24

    remove value(s) from a comma separated list from other value(s) from one other comma separated list

  25. 25

    Easy way to turn JavaScript array into comma AND Quotation Marks separated string list?

  26. 26

    Filter text from each file and turn it into a list of comma-separated values

  27. 27

    Turn comma-separated string into GetFiles SearchPattern

  28. 28

    Turn comma-separated string into GetFiles SearchPattern

  29. 29

    Turn a php array into comma separated array

HotTag

Archive