VBA question - re Substitute


Posted by Dominic on May 29, 2001 1:07 PM

Aladin introduced me to the substitute command in Excel
is there an equivalent command for VBA

Posted by Jerid on May 29, 2001 1:19 PM

Hi Dominic

Try Replace

Syntax

expression.Replace(What, Replacement, LookAt, SearchOrder, MatchCase, MatchByte)

expression Required. An expression that returns a Range object.

What Required String. The string to search for.

Replacement Required String. The replacement string.

LookAt Optional Variant. Can be one of the following XlLookAt constants: xlWhole or xlPart.

SearchOrder Optional Variant. Can be one of the following XlSearchOrder constants: xlByRows or xlByColumns.

MatchCase Optional Variant. True to make the search case sensitive.

MatchByte Optional Variant. Used only in Far East versions of Microsoft Excel. True to have double-byte characters match only double-byte characters. False to have double-byte characters match their single-byte equivalents.

Remarks

The settings for LookAt, SearchOrder, MatchCase, and MatchByte are saved each time you use this method. If you don't specify values for these arguments the next time you call the method, the saved values are used. Setting these arguments changes the settings in the Find dialog box, and changing the settings in the Find dialog box changes the saved values that are used if you omit the arguments. To avoid problems, set these arguments explicitly each time you use this method.

If the contents of the What argument are found in at least one cell on the sheet, this method returns True.



Posted by Dave Hawley on May 30, 2001 5:25 AM


Hi Dominic

I assume you are talking about the SUBSTITUTE function. If so you can use most of Excels WorksheetFunctions in VBA like below:

Sub TheSubstitute()
Dim sText As String
sText = Range("A1")
Range("A2") = WorksheetFunction.Substitute(sText, "u", "")

End Sub


To see what I mean type the word "Colour" in A1 and run the code.

Dave

OzGrid Business Applications