Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Junior Member
 
Posts: 2
Default Insert prefix and suffix to existing string

I have multiple columns and rows that need to have text added to the beginning and end of the existing string in the cell. There are too many columns to use a formula in the next column and I cannot use formatting to display the desired text because this file is going to be used by a program other than excel. Is there any way to use Find&Replace to add text before the existing string, then existing cell string, then additional text after existing string?
example:
existing string: 1.24567
want it to say <bol1.24567</bol

the string length will vary and I only want to do it for highlighted cells. Macro might be the way to go but I have limited use with macros.
thanks for your help!
  #2   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 1,045
Default Insert prefix and suffix to existing string

On Wed, 28 Nov 2012 00:49:37 +0000, schwachmama wrote:


I have multiple columns and rows that need to have text added to the
beginning and end of the existing string in the cell. There are too
many columns to use a formula in the next column and I cannot use
formatting to display the desired text because this file is going to be
used by a program other than excel. Is there any way to use
Find&Replace to add text before the existing string, then existing cell
string, then additional text after existing string?
example:
existing string: 1.24567
want it to say <bol1.24567</bol

the string length will vary and I only want to do it for highlighted
cells. Macro might be the way to go but I have limited use with macros.
thanks for your help!


A macro is definitely the way to go. The only question will consist of how to select the proper cells to add the tags. You write that those cells are "highlighted". You will need to explain what that means in order for the macro to automatically select the cells.
The example below shows a method, but it will do this for ALL of the cells on the active sheet that contain a constant. Obviously, your definition of "highlighted" and its incorporation into the selection process will be required to narrow that down.

To enter this Macro (Sub), <alt-F11 opens the Visual Basic Editor.
Ensure your project is highlighted in the Project Explorer window.
Then, from the top menu, select Insert/Module and
paste the code below into the window that opens.

To use this Macro (Sub), <alt-F8 opens the macro dialog box. Select the macro by name, and <RUN.

===================================
Option Explicit
Sub AddString()
Const sBefore As String = "<bol"
Const sAfter As String = "</bol"
Dim r As Range, c As Range

'need to set r equal to the highlighted cells
'below is only an example which sets r to
'every cell containing a constant

Set r = ActiveSheet.UsedRange.SpecialCells(xlCellTypeConst ants)
For Each c In r
If Left(c.Text, Len(sBefore)) < sBefore Then
c.Value = sBefore & c.Text
End If
If Right(c.Text, Len(sAfter)) < sAfter Then
c.Value = c.Text & sAfter
End If
Next c
End Sub
===================================
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
split prefix and suffix RayNDM83 Excel Discussion (Misc queries) 9 July 22nd 09 10:24 PM
Barcode suffix & Prefix Dimitris Excel Programming 4 March 11th 09 06:14 PM
How do I set an 'M' prefix to existing text in a column? muppetlover27 New Users to Excel 2 June 10th 08 01:41 PM
Prefix and Suffix Clare Excel Discussion (Misc queries) 2 January 30th 06 07:26 PM
adding the same prefix or suffix to a range of cells Betty Turvy Excel Discussion (Misc queries) 5 July 12th 05 05:13 PM


All times are GMT +1. The time now is 02:37 PM.

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"