Excel 2007 - Returning varying characters within a string

plsimmo

New Member
Joined
Aug 26, 2010
Messages
7
I have something like below.

<xxxxxxxxxxxxxxxxxxxxx>,
<xxxxxxxx>,
<xxxxxxxxxxxxxxx>,
<xxxxxxxxxxx>,
<xxxxxxxxxxxxxxxxxxxxxxxxx>,

<TABLE style="WIDTH: 134pt; BORDER-COLLAPSE: collapse" border=0 cellSpacing=0 cellPadding=0 width=179><COLGROUP><COL style="WIDTH: 134pt; mso-width-source: userset; mso-width-alt: 6546" width=179><TBODY><TR style="HEIGHT: 12.75pt" height=17><TD style="BORDER-BOTTOM: #e0dfe3; BORDER-LEFT: #e0dfe3; BACKGROUND-COLOR: transparent; WIDTH: 134pt; HEIGHT: 12.75pt; BORDER-TOP: #e0dfe3; BORDER-RIGHT: #e0dfe3" height=17 width=179>I want to return all the characters "only (X)s" within a string, that are all contained within <>,.

What would be the simplest way to achieve this?.

As always, thanks in advance for your assistance.
Regards
Paul
<XXXXXXXXXXXXXXXXXXXXXXXXXX>
</TD></TR><TR style="HEIGHT: 12.75pt" height=17><TD style="BORDER-BOTTOM: #e0dfe3; BORDER-LEFT: #e0dfe3; BACKGROUND-COLOR: transparent; HEIGHT: 12.75pt; BORDER-TOP: #e0dfe3; BORDER-RIGHT: #e0dfe3" height=17><XXXXXXXXXXXXXXXXXXXX></TD></TR><TR style="HEIGHT: 12.75pt" height=17><TD style="BORDER-BOTTOM: #e0dfe3; BORDER-LEFT: #e0dfe3; BACKGROUND-COLOR: transparent; HEIGHT: 12.75pt; BORDER-TOP: #e0dfe3; BORDER-RIGHT: #e0dfe3" height=17><XXXXXXXXXXXXXXXXXXXXXXXXX></TD></TR><TR style="HEIGHT: 12.75pt" height=17><TD style="BORDER-BOTTOM: #e0dfe3; BORDER-LEFT: #e0dfe3; BACKGROUND-COLOR: transparent; HEIGHT: 12.75pt; BORDER-TOP: #e0dfe3; BORDER-RIGHT: #e0dfe3" height=17><XXXXXXXXXXXXX></TD></TR><TR style="HEIGHT: 12.75pt" height=17><TD style="BORDER-BOTTOM: #e0dfe3; BORDER-LEFT: #e0dfe3; BACKGROUND-COLOR: transparent; HEIGHT: 12.75pt; BORDER-TOP: #e0dfe3; BORDER-RIGHT: #e0dfe3" height=17><XXXXXXXXXXXXXXXXXXXXXXXXX></TD></TR></TBODY></TABLE>
 
Last edited:

Excel Facts

Links? Where??
If Excel says you have links but you can't find them, go to Formulas, Name Manager. Look for old links to dead workbooks & delete.
If you had this string in cell A1
aaa<XXDX>dd
and you wanted the
XXDX component then you could use this UDF like
=extractx(A1)

If you wanted only
XXX
then remove the apostrophes from these two lines below
'.Pattern = "[^X]+"
' strTemp = .Replace(strTemp, vbNullString)
to add them to the code

Cheers

Dave

Code:
Function ExtractX(strIn As String) As String
    Dim objRegex
    Dim objRegMC
    Dim strTemp As String
    Set objRegex = CreateObject("vbscript.regexp")
    With objRegex
        .Pattern = "<(.+?)>"
        If .test(strIn) Then
            Set objRegMC = .Execute(strIn)
            strTemp = objRegMC(0).submatches(0)
            '.Pattern = "[^X]+"
           ' strTemp = .Replace(strTemp, vbNullString)
             ExtractX = strTemp
        Else
            ExtractX = "No Match"
        End If
    End With
End Function
 
Upvote 0

Forum statistics

Threads
1,224,544
Messages
6,179,430
Members
452,915
Latest member
hannnahheileen

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