Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Replace functions and wildcards

Status
Not open for further replies.

access101

Programmer
Sep 4, 2010
68
0
0
US
is it possible to use a replace function in vba that uses wildcards?

Me.T = Replace(T, "#.# mi", " mi")
 
I looked at the link but I'm not sure how to apply it to my replace statement?
 
Code:
Public Function myReplace(expression As String, findPattern As String, replace As String)
  'reference to Microsoft VBScript Regular Expressions
  Dim re As RegExp
  Set re = New RegExp  'Create the RegExp object
  re.Pattern = findPattern
  re.IgnoreCase = True
  re.Global = True
  myReplace = re.replace(expression, replace)
End Function

Public Sub testMyReplace()
  Dim T As String
  T = "1.2 mi"
  T = myReplace(T, "\d\.\d mi", "mi")
  MsgBox T
End Sub
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top