List of codes dinamically created

Samuel Otaviano

New Member
Joined
Dec 21, 2022
Messages
4
Office Version
  1. 2013
Platform
  1. Windows
Hi,





I'd like to create a list with numbered codes composed by an acronym related to the type of project wich is in another column. Just as the example in the attached image.

As the example in the image shows, it's possible to have more than one type of ptoject in the same cell, in those cases the code cell also has more than one code.

Any suggestion?
 

Attachments

  • table.png
    table.png
    11.5 KB · Views: 17

Excel Facts

Bring active cell back into view
Start at A1 and select to A9999 while writing a formula, you can't see A1 anymore. Press Ctrl+Backspace to bring active cell into view.
B5:
Excel Formula:
=TEXTJOIN(", ",1,IF($A$1:$A$3=LEFT(TRANSPOSE(FILTERXML("<x><y>"&SUBSTITUTE(A5,",","</y><y>")&"</y></x>","//y")),3),$B$1:$B$3,""))
This is an array formula. Hitting only Enter is not enough. You must press Ctrl+Shift+Enter together after paste.

1671696031183.png
 
Upvote 0
Thanks for your help.

Should i put this formula on B5 cell?

Cause i put it there and got an error.

1671760034793.png
 
Upvote 0
@Flashbond
The OP's profile shows Excel 2013 so they would not have TEXTJOIN.

@Samuel Otaviano
Welcome to the MrExcel board!
If Excel 2013 is correct then a formula solution for this sort of thing is not very practical.
Would a macro solution be acceptable?
 
Upvote 0
@Flashbond
The OP's profile shows Excel 2013 so they would not have TEXTJOIN.

@Samuel Otaviano
Welcome to the MrExcel board!
If Excel 2013 is correct then a formula solution for this sort of thing is not very practical.
Would a macro solution be acceptable?
Yes sure. If a macro can solve it, that's ok. I forgot to mention that i'm using Excel 2013.
 
Upvote 0
I forgot to mention that i'm using Excel 2013.
You didn't need to mention that as it is shown at the left of each of your posts. :)
1671763667401.png


If a macro can solve it, that's ok.
So, give this one a try.

VBA Code:
Sub Create_Codes()
  Dim d As Object
  Dim a As Variant, t As Variant
  Dim sCode As String
  Dim i As Long, j As Long
  
  Set d = CreateObject("Scripting.Dictionary")
  a = Range("B2", Range("B" & Rows.Count).End(xlUp))
  For i = 1 To UBound(a)
    t = Split(a(i, 1), ", ")
    For j = 0 To UBound(t)
      Select Case LCase(t(j))
        Case "website": sCode = "WEB"
        Case "graphic design": sCode = "DSG"
        Case "exhibition": sCode = "EXB"
        Case Else: sCode = "ZZZ"
      End Select
      d(sCode) = d(sCode) + 1
      t(j) = sCode & Format(d(sCode), "_000")
    Next j
    a(i, 1) = Join(t, ", ")
    Range("A2").Resize(UBound(a)).Value = a
  Next i
End Sub

My sheet before the code:

Samuel Otaviano.xlsm
AB
1CodeType
2website
3graphic design
4exhibition
5graphic design, exhibition
6website
7website, graphic design
Sheet1


.. and after:

Samuel Otaviano.xlsm
AB
1CodeType
2WEB_001website
3DSG_001graphic design
4EXB_001exhibition
5DSG_002, EXB_002graphic design, exhibition
6WEB_002website
7WEB_003, DSG_003website, graphic design
Sheet1
 
Upvote 0
It worked perfectly.

I'm not familiar with VBA but i know a bit of javascript, so i think i could understand the basic structure of this code. It's a good reference to begin to study VBA. :)

Thanks a lot!
 
Upvote 0
You're welcome. Thanks for the follow-up. :)
 
Upvote 0

Forum statistics

Threads
1,214,942
Messages
6,122,366
Members
449,080
Latest member
Armadillos

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