Separating Characters with Asterisk

Robert_Conklin

Board Regular
Joined
Jun 19, 2017
Messages
173
Office Version
  1. 365
Platform
  1. Windows
  2. MacOS
I have an excel workbook that uses VBA and user-forms that my end-users can submit maintenance requests for machines and spare parts. The cell that contains the manufacturer part number submitted needs to have an asterisk placed between each character in the cell. For instance: the mfg part number submitted is 562314578, and in another cell should be converted to *5*6*2*3*1*4*5*7*8*

Thanks in advance,
Rob
 

Excel Facts

Highlight Duplicates
Home, Conditional Formatting, Highlight Cells, Duplicate records, OK to add pink formatting to any duplicates in selected range.
Give this formula a try...

=TEXT(A1,REPT("\*0",LEN(A1)))&"*"
 
Last edited:
Upvote 0
Thanks Rick, the formula works, but I need it to incorporate into my VBA code.
 
Upvote 0
Thanks Rick, the formula works, but I need it to incorporate into my VBA code.
You did not give us any layout information, so I don't know if you want this for a single cell or for a range of cells and, if a range of cells, I don't know whether the range is horizontal or vertical. Here is a UDF (user defined function) that you can call from within your own code or from a worksheet cell (you apparently would want the former). Simply pass the value or cell reference for the text you want to add the asterisks to and the function will return the passed value with the asterisks inserted...
Code:
Function AddAsterisks(S As String) As String
  AddAsterisks = Format(S, Application.Rept("\*0", Len(S))) & "*"
End Function
 
Last edited:
Upvote 0
Not quite sure it gives you exactly what you want but try this.
Code:
Range("A1").Value = Replace(StrConv(Range("A1").Value, vbUnicode), Chr(0), "*")
 
Upvote 0
Not quite sure it gives you exactly what you want but try this.
Rich (BB code):
Range("A1").Value = "*" & Replace(StrConv(Range("A1").Value, vbUnicode), Chr(0), "*")
I think if you add what is shown in red above, it will work (assuming a single cell reference being required).
 
Upvote 0
I do have a table set up for the user-form (=$A$1:$AL$2). Column O is where the mfg part number is written. Column AL is titled SAP SEARCH CRITERIA, where the data from column O should be converted with the asterisk.

As a new entry is submitted through the user-form, another record in the table is created.
 
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