View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.programming
Peter T Peter T is offline
external usenet poster
 
Posts: 5,600
Default Code error message for Excel 97 users

Replace is n/a in Excel 07, along with various other string manipulation
functions. To cater for all versions do it like this

Dim sOld As String, sNew
'code

sOld = cell.Value
#If VBA6 Then ' Excel 2000 or later
sNew = Replace(Replace(Replace(sOld, "~", "~~"), "*", "~*"), "?", "~?")
#Else ' Excel 97
With Application.WorksheetFunction
sRep = .Substitute(.Substitute(.Substitute(sOld, _
"~", "~~"), "*", "~*"), "?", "~?")
End With
#End If
My_Range.AutoFilter Field:=FieldNum, Criteria1:="=" & sNew


Regards,
Peter T

"Monk" wrote in message
...
I get an error on the Replace part of the following code for people who are
still using Excel 97. I have tried using substitute instead but this also
does not seem to work. Any suggestions would be appreciated.

My_Range.AutoFilter Field:=FieldNum, Criteria1:="=" & _

Replace(Replace(Replace(cell.Value, "~", "~~"), "*", "~*"), "?", "~?")