decadence
Well-known Member
- Joined
- Oct 9, 2015
- Messages
- 525
- Office Version
- 365
- 2016
- 2013
- 2010
- 2007
- Platform
- Windows
Hi, can someone tell me the pattern for extracting variable length of letters starting from an alphanumeric string, The string will always start with letters first.
Here is the Code I am Using
Here is the Code I am Using
Code:
Private Sub Test()
Dim Rng As Range, Fnd As Range, x As Range
Dim strPattern As String, strInput As String
Dim RegEx As Object
Dim Arr As Variant
Dim i As Integer
Arr = Array("References", "Reference", "Ref's", "Refs", "Ref")
For i = LBound(Arr) To UBound(Arr)
Set Fnd = ActiveSheet.Columns.Find(What:=Arr(i), LookIn:=xlValues, lookat:=xlWhole, SearchOrder:=xlByRows, SearchDirection:=xlNext)
If Not Fnd Is Nothing Then
Set Rng = Range(Fnd.Offset(1), Cells(Rows.Count, Fnd.Column).End(xlUp))
End If
Next i
Set RegEx = CreateObject("VBScript.RegExp")
For Each x In Rng
'strPattern = <---------
If strPattern <> "" Then
strInput = x.Value
With RegEx
.Global = True
.MultiLine = True
.IgnoreCase = True
.Pattern = strPattern
End With
If RegEx.Test(strInput) Then
x.Offset(0, 7) = RegEx.Replace(strInput, "$1")
Else
x.Offset(0, 7) = "(Not matched)"
End If
End If
Next x
End Sub