View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.programming
Doug Glancy Doug Glancy is offline
external usenet poster
 
Posts: 770
Default VBA string funcs on left side of assignment?

That is interesting.

When you press F1 over the word "Mid" in XL2003 it gives a choice between
the Mid function and the Mid statement. It's the statement that allows you
to replace, and there is no analogous Left or Right statement (only
functions).

For overwriting the left part I guess I'd use:
s = "12345678"
s = "abc" & Right(s, Len(s) - 3)

or something like that.

hth,

Doug

wrote in message
...
Empirically I learned that the VBA function Mid() can be used on the
left side of an assignment. For example:

s = "12345678"
Mid(s, 4, 2) = "cd"

results in "123cd678". But the following does not work:

Left(s, 2) = "ab"
Right(s,2) = "ef"

Then I looked at the Help text for Mid, and I found nothing that
indicates that even Mid() can be on the left side of an assignment.

Where is written that I can use Mid() on the left side?

Is there something else that I should use to overwrite any part of a
string?

(Other than cumbersome concatenation like Mid(s,1,3) & "cd" & Mid(s,
6,3).)

Is there an easier way to overwrite the left and right parts of a
string other than using Mid()?