PDA

View Full Version : EXCEL syntax isue



McGabbarah
02-22-2020, 09:28 PM
Can I use the REPLACE function with a variable value for position?

What I vant to do is this

DIM mvar1 As long

Mvar1=(LEN(B1)-9)

REPLACE(b1,& mvar1, 1,”,”)

But can't seem to get the syntax sorted.

Any suggestions?

Paul_Hossler
02-23-2020, 07:27 AM
https://docs.microsoft.com/en-us/office/vba/Language/Reference/User-Interface-Help/replace-function



Replace(expression, find, replace, [ start, [ count, [ compare ]]])

The Replace function syntax has these named arguments (https://docs.microsoft.com/en-us/office/vba/Language/glossary/vbe-glossary#named-argument):


Part
Description


expression
Required. String expression (https://docs.microsoft.com/en-us/office/vba/Language/glossary/vbe-glossary#string-expression) containing substring to replace.


find
Required. Substring being searched for.


replace
Required. Replacement substring.


start
Optional. Start position for the substring of expression to be searched and returned. If omitted, 1 is assumed.


count
Optional. Number of substring substitutions to perform. If omitted, the default value is -1, which means, make all possible substitutions.


compare
Optional. Numeric value indicating the kind of comparison to use when evaluating substrings. See Settings section for values.






So in ...



REPLACE(b1,& mvar1, 1,”,”)



... you might want ....

Actually, I can't guess as to what you want. Might be best to add an example

snb
02-23-2020, 09:58 AM
Replace([B1], "1", "," ,len([B1])-9)