View Single Post
  #3   Report Post  
Posted to microsoft.public.excel.programming
david mcritchie david mcritchie is offline
external usenet poster
 
Posts: 691
Default use macro to insert characters at the beginning of a string

and the reason why what was done does not work is that
keystrokes like what you do to the formula bar is not recorded
only the resulting value (or formula). Recording a macro is
good for finding out what kind of instructions might help they
rarely can be used as generated.

You should have Option Explicit at the beginning of your
module in which case you will need to include the following
at the beginning of your macro. This will help you from
misusing code and to provide more meaningful error descriptions.

Dim c as Range

Because nothing in the macro is done to limit the scope within
the selection, your selection would have to include only the cells
you want to process, as opposed to selecting an entire column,
for instance.

Just in case you don't get exactly the kind of value you wanted:
Placing a "19" in front is making an assumption that your value
is a text string and you want the result as a text string as opposed
to a number. Since you only indicated your change was to the
wrong cell, I don't expect you actually have a problem in this regard.
--
HTH,
David McRitchie, Microsoft MVP - Excel [site changed Nov. 2001]
My Excel Pages: http://www.mvps.org/dmcritchie/excel/excel.htm
Search Page: http://www.mvps.org/dmcritchie/excel/search.htm

"Don Guillett" wrote in message ...
try
Sub addleading19()
For Each c In Selection
c.Value = "19" & c
Next
End Sub

"dcmackie" wrote ...
I need to add "19" to the beginning of the description of an asset to
correct two digit years to four.

I recorded my steps ie. F2 key, then home then right arrow the 19 then an
enter key to move down to the next cell.

If the next cell needs correction and I run the macro created by my
recording, rather than correcting the new cell, ie. adding "19" to the
beginning, it inserts the corrected contents of the previous cell on which
the macro was run.

Engaging the relative reference key does not help.