Manipulate strings within an Excel cell

NeoTheNerd

New Member
Joined
Nov 13, 2021
Messages
5
Office Version
  1. 2019
Platform
  1. MacOS
Hi All, I would like to build a list within a single cell from a sting stored another cell. The string has a semi colon delimiter ';' to separate the string. I need to extract the CN=*, and remove the remainder, in the adjacent cell.

I've tried the following, but with little joy

=SUBSTITUTE(A87,";CN=",CHAR(10))
=SUBSTITUTE(A87,",",CHAR(10))
=SUBSTITUTE(A87,",",CHAR(10)&",CN=")
=SUBSTITUTE(A87,";",CHAR(10))

How do I keep and list all the CN= entries and remove the remainder?

CN=User2,OU=blurb,OU=Test,DC=Test,DC=Testal;CN=User4,OU=blurb,OU=Test,DC=Test,DC=Testal;CN=User56,OU=blurb,OU=Test,DC=Test,DC=Testal;CN=User9,OU=blurb,OU=Test,DC=Test,DC=Testal;CN=Jane45 user,OU=blurb,OU=Test,DC=Test,DC=Testal;CN=User-Donna,OU=blurb,OU=Test,DC=Test,DC=Testal;CN=User76 smith,OU=blurb,OU=Test4,DC=Test,DC=Testal;CN=Pink Panther,OU=blurb,OU=Test,DC=Testing,DC=Testal;CN=Testuser78,OU=blurb,OU=Tester,DC=Test,DC=Testal;CN=great Scott,OU=blurb,OU=Test,DC=Test,DC=Local;CN=Leah Human,OU=blurb,OU=Test,DC=Test,DC=Testal;CN=Alan Desai,OU=blurb,OU=Test,DC=Test,DC=Testal;CN=Duff Beer,OU=Groups,OU=Test,DC=Test,DC=Testal;CN=Jane Doe,OU=Users,OU=Test76,DC=Test,DC=Testal;CN=simple user67,OU=Users,OU=Test,DC=Test,DC=Testal;CN=test O'Lord,OU=Users,OU=Test,DC=Concero,DC=TestalCN=User1
CN=User2
CN=User3
etc...
 

Attachments

  • Screenshot 2021-11-14 at 09.12.02.png
    Screenshot 2021-11-14 at 09.12.02.png
    112.4 KB · Views: 11

Excel Facts

Get help while writing formula
Click the italics "fx" icon to the left of the formula bar to open the Functions Arguments dialog. Help is displayed for each argument.
Does this user-defined function do what you want? To implement ..
1. Right click the sheet name tab and choose "View Code".
2. In the Visual Basic window use the menu to Insert|Module
3. Copy and Paste the code below (you can use the icon at the top right of the code pane below) into the main right hand pane that opens at step 2.
4. Close the Visual Basic window.
5. Enter the formula as shown in the screen shot below and copy down.
6. Your workbook will need to be saved as a macro-enabled workbook (*.xlsm)

VBA Code:
Function GetParts(s As String, Optional PartPrefix As String = "CN") As String
  GetParts = Replace(Join(Filter(Split(Replace(Replace("," & s, ";", ","), "," & PartPrefix, ",|" & PartPrefix), ","), "|"), ","), "|", "")
End Function

The standard function extracts the 'CN' parts as shown in column B. If you wanted other parts of the text extracted you can specify a second argument to the function as shown in column C.

NeoTheNerd.xlsm
ABC
1CN=User2,OU=blurb,OU=Test,DC=Test,DC=Testal;CN=User4,OU=blurb,OU=Test,DC=Test,DC=Testal;CN=User56,OU=blurb,OU=Test,DC=Test,DC=Testal;CN=User9,OU=blurb,OU=Test,DC=Test,DC=Testal;CN=Jane45 user,OU=blurb,OU=Test,DC=Test,DC=Testal;CN=User-Donna,OU=blurb,OU=Test,DC=Test,DC=Testal;CN=User76 smith,OU=blurb,OU=Test4,DC=Test,DC=Testal;CN=Pink Panther,OU=blurb,OU=Test,DC=Testing,DC=Testal;CN=Testuser78,OU=blurb,OU=Tester,DC=Test,DC=Testal;CN=great Scott,OU=blurb,OU=Test,DC=Test,DC=Local;CN=Leah Human,OU=blurb,OU=Test,DC=Test,DC=Testal;CN=Alan Desai,OU=blurb,OU=Test,DC=Test,DC=Testal;CN=Duff Beer,OU=Groups,OU=Test,DC=Test,DC=Testal;CN=Jane Doe,OU=Users,OU=Test76,DC=Test,DC=Testal;CN=simple user67,OU=Users,OU=Test,DC=Test,DC=Testal;CN=test O'Lord,OU=Users,OU=Test,DC=Concero,DC=TestalCN=User2,CN=User4,CN=User56,CN=User9,CN=Jane45 user,CN=User-Donna,CN=User76 smith,CN=Pink Panther,CN=Testuser78,CN=great Scott,CN=Leah Human,CN=Alan Desai,CN=Duff Beer,CN=Jane Doe,CN=simple user67,CN=test O'LordDC=Test,DC=Testal,DC=Test,DC=Testal,DC=Test,DC=Testal,DC=Test,DC=Testal,DC=Test,DC=Testal,DC=Test,DC=Testal,DC=Test,DC=Testal,DC=Testing,DC=Testal,DC=Test,DC=Testal,DC=Test,DC=Local,DC=Test,DC=Testal,DC=Test,DC=Testal,DC=Test,DC=Testal,DC=Test,DC=Testal,DC=Test,DC=Testal,DC=Concero,DC=Testal
CN
Cell Formulas
RangeFormula
B1B1=GetParts(A1)
C1C1=GetParts(A1,"DC")
 
Upvote 0
Welcome to the MrExcel Message Board!

Cross-posting (posting the same question in more than one forum) is not against our rules, but the method of doing so is covered by #13 of the Forum Rules.

Be sure to follow & read the link at the end of the rule too!

Cross posted at: Remove parts of a string ( ';' Semi-Colon Delimiter) and listing the remainder of the string in one cell
If you have posted the question at more places, please provide links to those as well.

If you do cross-post in the future and also provide links, then there shouldn’t be a problem.
 
Upvote 0
Hi Peter, I tried the function, but came back with a #Name? error.
is vba similar to vb.net?
 

Attachments

  • Screenshot 2021-11-14 at 15.39.28.png
    Screenshot 2021-11-14 at 15.39.28.png
    229 KB · Views: 6
Upvote 0
Should the function be something like this? Not that it works yet.


VBA Code:
Sub testC()

Dim LongString As String
Dim StringDelim() As String
Dim SubStringRemove1 As String
Dim SubStringRemove2 As String
Dim SubStringRemoveOU As String
Dim SubStringRemoveDC As String
Dim NewString As String

LongString = ("CN=User2,OU=blurb,OU=Test,DC=Test,DC=Testal;CN=User4,OU=blurb,OU=Test,DC=Test,DC=Testal;CN=User56,OU=blurb,OU=Test,DC=Test,DC=Testal;CN=User9,OU=blurb,OU=Test,DC=Test,DC=Testal;CN=Jane45 user,OU=blurb,OU=Test,DC=Test,DC=Testal;CN=User-Donna,OU=blurb,OU=Test,DC=Test,DC=Testal;CN=User76 smith,OU=blurb,OU=Test4,DC=Test,DC=Testal;CN=Pink Panther,OU=blurb,OU=Test,DC=Testing,DC=Testal;CN=Testuser78,OU=blurb,OU=Tester,DC=Test,DC=Testal;CN=great Scott,OU=blurb,OU=Test,DC=Test,DC=Local;CN=Leah Human,OU=blurb,OU=Test,DC=Test,DC=Testal;CN=Alan Desai,OU=blurb,OU=Test,DC=Test,DC=Testal;CN=Duff Beer,OU=Groups,OU=Test,DC=Test,DC=Testal;CN=Jane Doe,OU=Users,OU=Test76,DC=Test,DC=Testal;CN=simple user67,OU=Users,OU=Test,DC=Test,DC=Testal;CN=test O'Lord,OU=Users,OU=Test,DC=Concero,DC=Testal")
SubStringRemove1 = (",OU=*,")
SubStringRemove2 = (",DC=*,")

SubStringRemoveOU = Replace(LongString, ",OU=*,", "")
SubStringRemoveDC = Replace(SubStringRemoveOU, SubStringRemove2, "")
NewString = SubStringRemoveDC

StringDelim = Split(NewString, "; Chr(10)")

MsgBox StringDelim(0)

End Sub
 
Upvote 0

Forum statistics

Threads
1,214,601
Messages
6,120,465
Members
448,965
Latest member
grijken

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