Splitting and extracting characters from an excel string based on a character in a variable location

APInfa

New Member
Joined
Aug 2, 2021
Messages
7
Office Version
  1. 365
Platform
  1. Windows
I am attempting to create a code which will split a naming tag in different columns. I have been trying to use excel commands however I thing VBA might be the better option. I am attempting to input naming tags into a PI and I need to make the value of one character variable dependent on a PI command which I have working. Examples include BF_VYT1058, BF_TT1028A, and BF_TT1028B. What makes this difficult is I need to remove that "1" and each tag has a variable quantity on characters (as seen from the names) I need to extract the BF_TT or BF_VYT and the 058, 028A, or 028B from the tags. What commands could I use to extract this or what VBA code could I use?

PS: I can't just remove 1s specifically because there might be number code with another 1 (example: 1051). My final code is supposed to look like BF_VYT%@Selector%058 (when it is in PI).

Any and all help would be greatly appreciated.
 

Excel Facts

Pivot Table Drill Down
Double-click any number in a pivot table to create a new report showing all detail rows that make up that number
Upvote 0
Unfortunately this would replace the "1" everywhere within the left column.
That is not the case, it only replaces the 1st 1 in the string, as you can see in B5
 
Upvote 0
Hi,
VBA Code:
Sub test()
    Dim i&
    [b:b].ClearContents
    With CreateObject("Vbscript.Regexp")
        .Pattern = "(\D{2}\_\D{2,3}).(.+)"
        For i = 3 To Cells(Rows.Count, 1).End(3).Row
            If .test(Cells(i, 1).Value) Then
                Cells(i, 2).Value = (.Replace(Cells(i, 1).Value, "$1%@Selector@%$2"))
            End If
        Next i
    End With
End Sub
 
Upvote 0

Forum statistics

Threads
1,214,947
Messages
6,122,411
Members
449,081
Latest member
JAMES KECULAH

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