Formula Or Code For Below Results In Columns B & C.

Dazzawm

Well-known Member
Joined
Jan 24, 2011
Messages
3,786
Office Version
  1. 365
Platform
  1. Windows
I have column A as laid out below. I would like the results that are in column B and C please. If it is a formula a UDF would be advantageous. Thanks.

New Numbers Template.xlsx
ABC
1
231498N31498,31498N,31498R31498-OE,31498-OS
331506N31506,31506N,31506R31506-OE,31506-OS
434021N34021,34021N,34021R34021-OE,34021-OS
516324N16324,16324N,16324R16324-OE,16324-OS
630629N30629,30629N,30629R30629-OE,30629-OS
716037N16037,16037N,16037R16037-OE,16037-OS
831499N31499,31499N,31499R31499-OE,31499-OS
Sheet1
 

Excel Facts

Which lookup functions find a value equal or greater than the lookup value?
MATCH uses -1 to find larger value (lookup table must be sorted ZA). XLOOKUP uses 1 to find values greater and does not need to be sorted.
Pretty easy with some basic functions.

Formula for cell B2 (and copy down):
Excel Formula:
=LET(x,LEFT(A2,5),x&","&x&"N,"&x&"R")

Formula for cell C2 (and copy down):
Excel Formula:
=LET(x,LEFT(A2,5),x&"-OE,"&x&"-OS")
 
Upvote 0
Pretty easy with some basic functions.

Formula for cell B2 (and copy down):
Excel Formula:
=LET(x,LEFT(A2,5),x&","&x&"N,"&x&"R")

Formula for cell C2 (and copy down):
Excel Formula:
=LET(x,LEFT(A2,5),x&"-OE,"&x&"-OS")
Both formulas leave of the last two numbers like below.

Cell Formulas
RangeFormula
B2:B8B2=LET(x,LEFT(A2,5),x&","&x&"N,"&x&"R")
C2:C8C2=LET(x,LEFT(A2,5),x&"-OE,"&x&"-OS")
 
Upvote 0
That is the danger when the example you post are not representative of all the data you may be working with!
In your original example, all your entries were exactly 6 characters long. In this last one, it is 7 characters long.
It is really important that you give us ALL the important details, if you want an answer that will work for all your cases.
(The key to getting a good answer is to ask a good, complete question).

If your entries could have various lengths, and it is just the last character that should be dropped, then change the formulas to this:

For cell B2:
Excel Formula:
=LET(x,LEFT(A2,LEN(A2)-1),x&","&x&"N,"&x&"R")

For cell C2:
Excel Formula:
=LET(x,LEFT(A2,LEN(A2)-1),x&"-OE,"&x&"-OS")

1718106439060.png
 
Upvote 0
That is the danger when the example you post are not representative of all the data you may be working with!
In your original example, all your entries were exactly 6 characters long. In this last one, it is 7 characters long.
It is really important that you give us ALL the important details, if you want an answer that will work for all your cases.
(The key to getting a good answer is to ask a good, complete question).

If your entries could have various lengths, and it is just the last character that should be dropped, then change the formulas to this:

For cell B2:
Excel Formula:
=LET(x,LEFT(A2,LEN(A2)-1),x&","&x&"N,"&x&"R")

For cell C2:
Excel Formula:
=LET(x,LEFT(A2,LEN(A2)-1),x&"-OE,"&x&"-OS")

View attachment 112545
Sorry that was my fault, thanks for your time. A UDF is not possible I suppose in this instance where there are 2 formulas?
 
Upvote 0
Sorry that was my fault, thanks for your time. A UDF is not possible I suppose in this instance where there are 2 formulas?
A UDF would be possible, but it is usually recommended to never use a UDF when a simply formula will do.
You want to do something distinctly different in column B versus column C, so you would need to different UDFs anyway (unless you wanted to make one longer complex one).
So I really see no advantage to using a UDF here.

If you are looking for a VBA solution, I think a Procedure would probably better than a UDF here, where you loop through all the rows with data in column A and put the desired results in columns B and C. However, the caveat there is if you change the data in column A afterwards, you would need to re-run the VBA code (or use an Worksheet_Change Event Procedure which would update it in real-time).
 
Upvote 0
That was an error on my part, the WA in front would never be there I forgot to remove it.
 
Upvote 0
If you like UDF,
Use in cell like
B2;
=FILTER(WA(A2:A100),A2:A100<>"")
Code:
Function WA(r As Range)
    Dim a, i As Long, s
    a = r.Value
    ReDim Preserve a(1 To UBound(a, 1), 1 To 2)
    For i = 1 To UBound(a, 1)
        s = a(i, 1)
        If s <> "" Then
            s = Left$(s, 5)
            a(i, 1) = Join(Array(s, s & "N", s & "R"), ",")
            a(i, 2) = Join(Array(s & "-OE", s & "-OS"), ",")
        End If
    Next
    WA = a
End Function
 
Upvote 0
A UDF would be possible, but it is usually recommended to never use a UDF when a simply formula will do.
You want to do something distinctly different in column B versus column C, so you would need to different UDFs anyway (unless you wanted to make one longer complex one).
So I really see no advantage to using a UDF here.

If you are looking for a VBA solution, I think a Procedure would probably better than a UDF here, where you loop through all the rows with data in column A and put the desired results in columns B and C. However, the caveat there is if you change the data in column A afterwards, you would need to re-run the VBA code (or use an Worksheet_Change Event Procedure which would update it in real-time).
I would be obliged with a VBA, I will use on many different files then and keep in my personal macro workbook.
 
Upvote 0

Forum statistics

Threads
1,224,823
Messages
6,181,181
Members
453,022
Latest member
Mohamed Magdi Tawfiq Emam

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