0 votes
in VBA by Skilled (741 points)

Cell A1 has this text: Now is the time for you.

As described in Characters object (Excel)
Range("A1").Characters(12,4).Text returns this 4-letter string: time

Characters.Insert method (Excel) seems to say that 
v = Range("A1").Characters(12,4).Insert("day") inserts the string day preceding the selected characters time,
so the expected result is: Now is the daytime for you.
But the actual result is Now is the day for you.

Why?

1 Answer

+1 vote
by Skilled (741 points)
edited by
 
Best answer

Characters.Insert method (Excel) is misleading. The Insert method doesn't insert; it actually replaces and should be called the Characters.Replace method. However, if you really want to insert use this: 
v = Range("A1").Characters(12,0).Insert("day") to get the result: 
Now is the daytime for you.

To summarize: Range(...).Characters(Start, Length).Insert actually replaces Length characters beginning at Start; use zero Length to insert.

By the way, you might be interested in my new web site: My Excel Toolbox

Welcome to wellsr Q&A
wellsr Q&A is the VBA and Python programming community that rewards you for learning how to code.

Getting Started
Register
VBA Cheat Sheets (On Sale Now)

Earn free prizes for asking VBA and Python questions and for answering questions asked by others in our community.

Looking for something else? Hire our professional VBA Help, instead.

What makes us different?
Our points system rewards you with a chance for free gifts based on the quality of your questions and answers. All you have to do is post and you could get rewarded, like these members:

ParserMonster $25 Amazon Gift Card
Hightree $10 Amazon Gift Card
Thales1 $10 Amazon Gift Card
runfunke $10 Amazon Gift Card
coolag $10 Amazon Gift Card
Siew Hun $10 Amazon Gift Card

So, why don't you join us? It really is an encouraging way to motivate members in our VBA and Python community.

Register

For more programming tips visit the VBA Tutorials Blog and the Python Tutorials Blog.

...