Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Add common prefix to all cells in Excel

Tags:

excel

I have a column with some text in each cell.
I want to add some text, for example "X", at the start of all cells. For example:

A             B -----  >>>>  ---- 1            X1 2            X2 3            X3 

What is the easiest way to do this?

like image 668
LIX Avatar asked Apr 24 '10 06:04

LIX


People also ask

How do I add a batch prefix in Excel?

Method 1: Use “&” Formula To start with, select a blank cell in another column, such as Cell C1. Then, in the selected cell, type the formula in the pattern of = “Prefix ” & Cell, such as the following instance.


1 Answers

Type this in cell B1, and copy down...

="X"&A1 

This would also work:

=CONCATENATE("X",A1) 

And here's one of many ways to do this in VBA (Disclaimer: I don't code in VBA very often!):

Sub AddX()     Dim i As Long      With ActiveSheet     For i = 1 To .Range("A65536").End(xlUp).Row Step 1         .Cells(i, 2).Value = "X" & Trim(Str(.Cells(i, 1).Value))     Next i     End With End Sub 
like image 167
mechanical_meat Avatar answered Sep 24 '22 06:09

mechanical_meat