Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default use macro to insert characters at the beginning of a string

I thought his would be the simplest of macros !

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.

  #3   Report Post  
Posted to microsoft.public.excel.programming
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.





  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,337
Default use macro to insert characters at the beginning of a string

David, I did test with a number and text and number only.

Sub addleading19()
For Each c In Selection
c.Value = "19" & c
Next
End Sub


--
Don Guillett
SalesAid Software

"David McRitchie" wrote in message
...
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.







  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 691
Default use macro to insert characters at the beginning of a string

Hi Don,
I guess I used too many you's referring to two different
people. But there is the *possibility* that what he had
were dates, or that "numbers" had leading zeros.
In any case I would not want to encourage anyone
to remove Option Explicit
from a module, because the posting sounded like he
was new to macros but know how to install and use.

"Don Guillett" wrote...
David, I did test with a number and text and number only.

Sub addleading19()
For Each c In Selection
c.Value = "19" & c
Next
End Sub


--
Don Guillett
SalesAid Software

"David McRitchie" wrote in message
...
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.









Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
deleting characters from beginning of call fazz Excel Discussion (Misc queries) 7 May 21st 10 02:34 PM
Insert Leading Characters If String Is Only 7 Characters Paperback Writer Excel Discussion (Misc queries) 2 April 21st 09 09:07 PM
Weird characters at beginning of cell jdelcour Excel Discussion (Misc queries) 3 July 18th 06 06:51 PM
Insert characters in a text string jamae918 Excel Worksheet Functions 1 March 28th 05 10:04 PM
add characters to beginning of text Natalie Excel Worksheet Functions 3 March 4th 05 12:56 PM


All times are GMT +1. The time now is 08:55 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"