Macro for adding text to existing text

J

J Heuer

I'm trying to create a macro which will add a short text string to the
existing text in every cell selected, and it looks like this requires
some knowledge of Visual Basic (which I lack). Any suggestions?
 
J

JE McGimpsey

XL macros are written in Visual Basic for Applications. Here's one way
to do the addition. Type OPT-F11 to enter the Visual Basic Editor.
Choose Insert/Module to insert a regular code module, and type or paste
this in:

Public Sub AddText()
Const sADDTEXT As String = " Text to Add"
Dim rCell As Range
For Each rCell In Selection
rCell.Value = rCell.Value & sADDTEXT
Next rCell
End Sub

Change the value of sADDTEXT to suit. If you want to prepend the text
instead, use

rCell.Value = sADDTEXT & rCell.Value

instead.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top