Solved

Excel prepend character

Posted on 2013-12-04
6
291 Views
Last Modified: 2013-12-04
I have a column of data and would like to prepend the first character with a special character like # or $. Is there any automated way to do this, thanks

column1
data1
data2
data3
data4

I would like for this to become without going to each row.

#data1
#data2
#data3
0
Comment
Question by:techdrive
6 Comments
 
LVL 39

Accepted Solution

by:
nutsch earned 500 total points
ID: 39695987
Formula way:
Create a new column with the formula ="#" & A1
Extend the formula down by a copy paste
Copy the result then paste values over your initial data
Remove the temporary column

Macro way: Select your cells then run the attached code

sub AddLetters
dim cl as range
for each cl in selection.cells
    cl="#"&cl.value
next cl
end sub

Open in new window


Thomas
0
 
LVL 19

Expert Comment

by:jss1199
ID: 39696014
Using macro...
1. Select the range that you want to insert the prefix or suffix.
2. Click Developer > Visual Basic, click Insert > Module, and then input the following code:
Sub AddPrefix()
'Updateby20131204
Dim Rng As Range
Dim WorkRng As Range
Dim addStr As String
On Error Resume Next
xTitleId = "AddPrefixToCellRange"
Set WorkRng = Application.Selection
Set WorkRng = Application.InputBox("Range", xTitleId, WorkRng.Address, Type:=8)
addStr = Application.InputBox("Add text", xTitleId, "", Type:=2)
For Each Rng In WorkRng
    Rng.Value = addStr & Rng.Value
Next
End Sub

Open in new window

3. Run the macro AddPrefix and enter the range that you want to insert the prefix and then enter the character(s) to add - this can be used for your current situation and others that may require different prefixes without modifying the macro
0
 
LVL 4

Expert Comment

by:andrew_man
ID: 39696017
No need VBA

Just type

="#"&A1

then, copy and paste value
0
Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

 
LVL 19

Expert Comment

by:jss1199
ID: 39696043
agreed, andrew but the OP did not want to touch each row...
0
 
LVL 19

Expert Comment

by:regmigrant
ID: 39696045
All of the above will work but if this is a one off and the 'data' part is common you can just use find/replace - find 'data', replace with '#data'

Reg
0
 
LVL 32

Expert Comment

by:Rob Henson
ID: 39696167
OP won't have to touch each row but will only need to insert formula in first row and then fill down, using either Ctrl + D or double click the fill handle.

Then copy paste special.
0

Featured Post

Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

A little background as to how I came to I design this code: Around 5 years ago I designed an add-in that formatted Excel files to a corporate standard, applying different cell colours and font type depending on whether the cells contained inputs,…
Convert between Excel file formats (.XLS, .XLSX, .XLSM) with/without macro option David Miller (dlmille) Intro Over this past Fall, I've had the opportunity to see several similar requests and have developed a couple related solutions associate…
The viewer will learn how to use a discrete random variable to simulate the return on an investment over a period of years, create a Monte Carlo simulation using the discrete random variable, and create a graph to represent the possible returns over…
This Micro Tutorial will demonstrate how to use longer labels with horizontal bar charts instead of the vertical column chart.

785 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question