Logo 
Search:

MS Office Answers

Ask Question   UnAnswered
Home » Forum » MS Office       RSS Feeds
  Question Asked By: Oscar Montgomery   on Feb 01 In MS Office Category.

  
Question Answered By: Aaron Evans   on Feb 01

The problem is with the definition of "Range".
the range is a "object".
the range object:
"Represents a cell, a row, a column, a selection of cells containing one or more
contiguous blocks of cells" (msoffice help)
this object has Properties. the DEFAULT property happens to be Value.
It isn't REALLY a variable  that can be set to a string, it merely points to the
location and the PROPERTY is set to the value of the cell.
MID is a function that:
"Returns a Variant (String) containing a specified number of characters  from a
string" (MSOffice Help)
It wasn't really intended to be set equal to ANYTHING.
Like any other function, you pass it values (by reference),
it does it's MicroSoft Magic, and returns the result.
I think the fact that John's example:
Tmpstr = Range("E3")
Mid(Tmpstr, 20, 3) = "IKL"
Range("E3") = Tmpstr
works at all is unintentional (on MicroSoft's part).
In fact, it is not something I would've even TRIED because it clearly defies my
definition of how a function should work.
To me, it is like saying my car is out of gas, so I'll pour Diet Coke into the
tank. Clearly, the car is designed to run on fuel that BURNS, so why should I
think that something that doesn't burn will work?
Logically, what I would've done is something like:
Range("E2") = Left(Range("E2").Value, 20) & "IKL" & _
Mid(Range("E2").Value, 24, Len(Range("E2")))
Here, you're taking the leftmost 20 characters, concatenating "IKL", then using
the MID function to return the characters following the 23 character to the end
of the string  (the LEN() function is overkill, it will stop when it gets to the
end).

Share: 

 

This Question has 3 more answer(s). View Complete Question Thread

 
Didn't find what you were looking for? Find more on Mid statement Or get search suggestion and latest updates.


Tagged: