1

I've got a string of text which are a grouping of circuit numbers. For instance, "2,4,6,8"

Each of these are independent circuits with independent values (ampacities).

I have these values all described in a table wherein one column is the CKT # (2) and the column to its right is the ampacity (20).

So if I have circuits 2, 4, 6, and 8, and they have ampacities of 20, 25, 30, & 40 respectively, I want Excel to be able to look at the value for "2" and replace it with "20", and 4, "25", 6, "30", and so on.

So I'd start with "2,4,6,8" and end with "20,25,30,40"

Is there a way to do this?

Thank you!

3
  • 1
    Welcome to SU! If you are ok with a solution that uses several columns, you can split each group of circuit numbers into several columns and then just use a VLOOKUP on your ckt # -> ampacity table. However, if you need a one-line conversion, you may be better off with a custom VBA function. Apr 9, 2019 at 2:03
  • I did something similar a while ago, with two columns and VLOOKUP as Isky mentioned. On a sheet named "Database" I have the number in coulmn A and then a value to return in column B. Then, in my first sheet, I enter the number I want to fetch in column A, and in column B the value is returned by the function: =IFERROR(VLOOKUP(A1,Database!A:B,2,TRUE)," ") (For B1, and so on down the page) Apr 9, 2019 at 5:51
  • Are you trying to do : =INDEX({20,25,30,40},1,MATCH(A1,{2,4,6,8},0)) ?
    – p._phidot_
    Apr 9, 2019 at 7:48

1 Answer 1

0

First enter the following user defined function in a standard module:

Public Function xLate(s As String, rng As Range) As String
    Dim temp As String, arr(), i As Long

    temp = "," & s & ","
    arr = rng
    For i = LBound(arr, 1) To UBound(arr, 1)
        temp = Replace(temp, "," & arr(i, 1) & ",", "," & arr(i, 2) & ",")
    Next i
    xLate = Mid(temp, 2, Len(temp) - 2)
End Function

Then place your translation table somewhere in the worksheet (say F1:G6). Then with data in A1, in B1 enter:

=xlate(A1,F1:G6)

enter image description here

As you see from the example, the function replaces each element in a comma separated string with another element defined in the table.

If a source element does not appear in the table, it is left unchanged.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .