How can I append text to every cell in a column in Excel? I need to add a comma (",") to the end.
Example:
email#address.com turns into email#address.com,
Data Sample:
m2engineers#yahoo.co.in
satishmm_2sptc#yahoo.co.in
threed_precisions#rediffmail.com
workplace_solution#yahoo.co.in
threebworkplace#dataone.in
dtechbng#yahoo.co.in
innovations#yahoo.co.in
sagar#mmm.com
bpsiva#mmm.com
nsrinivasrao#mmm.com
pdilip#mmm.com
vvijaykrishnan#mmm.com
mrdevaraj#mmm.com
b3minvestorhelpdesk#mmm.com
sbshridhar#mmm.com
balaji#mmm.com
schakravarthi#mmm.com
srahul1#mmm.com
khramesh2#mmm.com
avinayak#mmm.com
rockindia#hotmail.com
See if this works for you.
All your data is in column A (beginning at row 1).
In column B, row 1, enter =A1&","
This will make cell B1 equal A1 with a comma appended.
Now select cell B1 and drag from the bottom right of cell down through all your rows (this copies the formula and uses the corresponding column A value.)
Select the newly appended data, copy it and paste it where you need using Paste -> By Value
That's It!
It's a simple "&" function.
=cell&"yourtexthere"
Example - your cell says Mickey, and you want Mickey Mouse. Mickey is in A2. In B2, type
=A2&" Mouse"
Then, copy and "paste special" for values.
B2 now reads "Mickey Mouse"
It's simple...
=CONCATENATE(A1, ",")
Example: if email#address.com is in the A1 cell then write in another cell: =CONCATENATE(A1, ",")
email#address.com After this formula you will get email#address.com,
For remove formula: copy that cell and use Alt + E + S + V or paste special value.
There is no need to use extra columns or VBA if you only want to add the character for display purposes.
As this post suggests, all you need to do is:
Select the cell(s) you would like to apply the formatting to
Click on the Home tab
Click on Number
Select Custom
In the Type text box, enter your desired formatting by placing the number zero inside whatever characters you want.
Example of such text for formatting:
If you want the cell holding value 120.00 to read $120K, type $0K
Pretty simple...you could put all of them in a cell using the concatenate function:
=CONCATENATE(A1, ", ", A2, ", ", and so on)
Highlight the column and then Ctrl + F.
Find and replace
Find ".com"
Replace ".com, "
And then one for .in
Find and replace
Find ".in"
Replace ".in, "
Simplest of them all is to use the "Flash Fill" option under the "Data" tab.
Keep the original input column on the left (say column A) and just add a blank column on the right of it (say column B, this new column will be treated as output).
Just fill in a couple of cells of Column B with actual expected output. In this case:
m2engineers#yahoo.co.in,
satishmm_2sptc#yahoo.co.in,
Then select the column range where you want the output along with the first couple of cells you filled manually ... then do the magic...click on "Flash Fill".
It basically understands the output pattern corresponding to the input and fills the empty cells.
I just wrote this for another answer:
You would call it using the form using your example: appendTextToRange "[theRange]", ",".
Sub testit()
appendTextToRange "A1:D4000", "hey there"
End Sub
Sub appendTextToRange(rngAddress As String, append As String)
Dim arr() As Variant, c As Variant
arr = Range(rngAddress).Formula
For x = LBound(arr, 1) To UBound(arr, 1)
For y = LBound(arr, 2) To UBound(arr, 2)
Debug.Print arr(x, y)
If arr(x, y) = "" Then
arr(x, y) = append
ElseIf Left(arr(x, y), 1) = "=" Then
arr(x, y) = arr(x, y) & " & "" " & append & """"
Else
arr(x, y) = arr(x, y) & " " & append
End If
Next
Next
Range(rngAddress).Formula = arr
End Sub
Select the range of cells, type in the value and press Ctrl + Enter.
This, of course, is true if you want to do it manually.
Put the text/value in the first cell, then copy the cell, mark the whole colum and 'paste' the copied text/value.
This works in Excel 97 - sorry no other version available on my side...
This is addition to #Edward-Leno 's answer for more detail/explanation and cases where the text cells are formulas instead of values, and you want to retain the original formula.
Suppose your cells look like this (formulas)
="email" & "#" & "address.com"
=A1 & "#" & C1
instead of this (values)
email#address.com
If "email" and "address.com" were some cells like A1 is the email and C1 is the address.com part, then you'd have something like =A1&"#"&C1 which would be important to retain since A1 and C1 might not be constants and can change, so the comma-concatenated values would change, like if C1 is "gmail.com", "yahoo.com", or something else based on its formula.
Values method: The following steps will successfully append text but only keep the value using a scratch column (this works for rows, too, but for simplicity, the directions are for columns)
Assume column A is your data.
In scratch column B, start anywhere like the top of column B such as at B1 and put this formula:
=A1&","
Essentially, the "&" is the concatenation operator, combining two strings together (numbers are converted to strings). The "," can be adjusted to ", " if you want a space after the comma.
Copy the cell B1 and copy it down to all other cells in column B, either by clicking at the bottom right of cell B1 and dragging down, or copying with "Ctrl+C" or right-click > "Copy".
Paste B1 to all cells in column B with "Ctrl+V" or right-click > "Paste Options:" > "Paste". You should see the data looking like you intended.
Copy all cells in column B and paste them to where you want via right-click > "Paste Options:" > "Values". We select values so it doesn't mess up any formatting or conditional formatting
Formula retention method: The following steps will successfully retain the original formula. The process is similar to the values method, and only step 2, the formula used to concatenate the comma, changes.
Assume column A is your data.
In scratch column B, start anywhere like the top of column B such as at B1 and put this formula:
=FORMULATEXT(A1)&","
FORMULATEXT() grabs the formula of the cell as opposed to the value of it, so a simple example would be that it grabs =2+2 instead of 4, or =A1 & "#" & C1 where A1 is "Bob" and C1 is "gmail.com" instead of Bob#gmail.com.
Note: This formula only works for Excel versions 2013 and greater. For alternative equivalent solutions for Excel 2010 and older, see this superuser answer: https://superuser.com/a/894441/495155
Copy the cell B1 and copy it down to all other cells in column B, either by clicking at the bottom right of cell B1 and dragging down, or copying with "Ctrl+C" or right-click > "Copy".
Paste B1 to all cells in column B with "Ctrl+V" or right-click > "Paste Options:" > "Paste". You should see the data looking like you intended.
Copy all cells in column B and paste them to where you want via right-click > "Paste Options:" > "Values". We select values so it doesn't mess up any formatting or conditional formatting
Type it in one cell, copy that cell, select all the cells you want to fill, and paste.
Alternatively, type it in one cell, select the black square in the bottom-right of that cell, and drag down.
Related
I'm new to stack overflow so I apologize if this is a horrendously stupid question. I am wondering if there is a function or way to code a function in excel that will combine a column of cells with plain text and convert them into one cell with the text on a single line? Specifically I want to convert a column of random numbers into a single line of text and insert SPACE+AND+SPACE between them.
Ex.
15133484
12345188
12345888
to
15133484 AND 12345188 AND 12345888
Currently I am copying and pasting all this information into google and then into Word and using find/replace and it is taking forever everytime. If it is possible to just get Excel to do this for me that would be amazing.
Thanks!
If you have Office 365 Excel use TEXTJOIN():
=TEXTJOIN(" AND ",TRUE,A:A)
otherwise one would have to use:
=A1 & " AND " & A2 & " AND " & A3
Or one can use a helper column, B1 put:
=A1
put this in B2 and copy down:
=IF(A2<>"",B1 & " AND " & A2,B1)
And grab the last cell in column B.
A little late, but still:
Reference here
Step 1:
=concatenate(transpose(rngBeg:rngEnd & " AND "))
Step 2:
highlight the transpose statement and then press F9, which substitutes the actual values for the formula.
Step 3:
Remove the curly braces, { }, from the formula. The cell will display the range of reference cells combined with whatever separator chosen after the ampersand sign.
Not a "live" formula, but still far easier than manually concatenating a range of values.
Press ALT+F11 to open Microsoft Visual Basic for Applications,
Insert-> Module
Paste this:
Function Combine(WorkRng As Range, Optional Sign As String = " AND ") As String
Dim Rng As Range
Dim OutStr As String
For Each Rng In WorkRng
If Rng.Text <> "," Then
OutStr = OutStr & Rng.Text & Sign
End If
Next
Combine = Left(OutStr, Len(OutStr) - 5)
End Function
In any cell type =Combine(Range)
i.e.
=Combine(A1:A500)
use concat function if you can add an additional column in the excel like this:
=CONCAT(D3:E5)
Attached sample image with input, additional column, output and formula
I assume you want to merge the data in the 3 cells into a single cell with a space between the 3 data set.
If that is the case then you can do it simply by using the Concatenate function in excel.
In the above example, you have data in Cells A1, A2 & A3.
Cell C1 has the merged data. As you can see, we have used CONCATENATE Function.
The space has been defined in Double quotes. So if you need a Hyphen (-), you can put that in Double Quotes with space “ - ” and it will display the result with Sanjay - Singh - Question
Hope this helps.
I have a column of data that need to be filled. The formula should go like:
SUM(A10 + B10)
SUM A20 + B20
SUM A30 + B30
. .
. .
I have no idea on how to do the setup. Appreciate for any help :)
You're looking for the INDIRECT worksheet function. You need to nest it within the SUM function and you'll get what you're after. E.g. assuming you're in a cell in the very first row on a worksheet, you type:
=SUM(INDIRECT("A" & ROW()*10), INDIRECT("B" & ROW()*10))
One option is to use INDEX function here, it's not volatile like INDIRECT and will still work if you insert rows or columns, e.g. in cell C2 use this formula copied down
=SUM(INDEX(A$1:B$1000,ROWS(C$2:C2)*10,0))
.....or alternatively, this method will actually give you the formula =SUM(A10,B10) in the first cell and =SUM(A20,B20) in the next cell etc.
Put this formula in C2 and copy down as far as required
="=SUM(A"&ROWS(C$2:C2)*10&",B"&ROWS(C$2:C2)*10&")"
Select whole range > Right Click > Copy > Right Click > Paste Special > Values > OK > ENTER
That creates text versions of the required formulas - to convert to actual formulas do an "Edit/Replace" and replace = with =
Use =SUM(A10,B10) in the first cell and the drag the cell content to all the below cells if you want to fix a attribute like column number than put a $ symbol in front of it eg =SUM($A10,$B10). Similarly, for rows use =SUM(A$10,B$10).
I would probably do something like this, only because I prefer VBA.
Sub FillSheet()
Dim j, k
j = 10
k = 1
For j = 10 to 500 Step 10 '<<--Starts at 10, then 20, 30, etc up to 500
Worksheets("YourWorkSheetName").Range("A" & k).Formula = "=SUM(A" & j & ":B" & j & ")"
k = k +1
Next j
End Sub
Modify according to your requirements. Change "A" if want the formula in another column. Change "500" to however many lines you need.
I'm trying to do a formula where it is CELL / 127.05 - 1 and apply this to columns H-Y and rows 2-455. I'm not really familiar with excel and am going about this calculation cell by cell. Also, I'm running into a "circular" problem where certain cells rely on another, if anyone could explain this.
Thanks ahead of time!
A formula in a cell generally cannot refer to itself. If you want to apply an operation to an existing range of data, you can, but it is quite rare and surely not in the spirit of a spreadsheet app.
Regarding your question, you could
- enter a value (127.05) anywhere in an empty cell,
- then copy that cell
- then select the range you want to modify
- then select Paste Special / Divide (or any other operation)
As I said above, it sounds like you want to apply that formula to same cell that contains the value you want to act on. That will not work. results cells (i.e. containing your conclusions) will contain the formula and a reference to the cell it will act on. (Although I am using a smaller area for illustration, the principles will apply to your specific application)
Note - I used the randbetween(min,max) function to populate all the data cells. this is why each image contains different data. You of course will use cells containing static data.
For a simple example:
Say you put the value 127.05 in cell A1, and have a range of data cells, like this:
In cell F1, enter = b1/$a$1 - 1 like this:
Note, the $ signs tell Excel to use a static location cell reference. After hitting enter, the value -0.85045 will appear. Now, click and hold your mouse starting in that cell, and drag your mouse down to row 14 release the mouse button and hit keys <ctrl><d>. Your sheet should look like this:
Hold down the shift key while the column is still selected, and hit the right arrow key 3 times, Your sheet should look like this:
release the shift key and while the cells are all highlighted, hit keys <ctrl><r>. The results are here:
One way is to highlight the column (or specific range) you want to apply the formula to, press F2 to access the formula bar, type the formula, and press CTRL+D to paste DOWN if the range is vertical and CTRL+R to paste ACROSS if the range is horizontal. Say that your data looks like this:
A B
--- ---
5 A1/127-1
4
7
8
Then in order to copy the formula down, highlight A2 to A4 and press CTRL+D, or highlight B1, and click on the bottom right of the box that comes up surrounding the cell.
If you wanted to simply replace the values in A with their formula values you would still have to use Column B as a 'helper' column, rather than entering the value right into the cell. This is in fact exactly what is giving you the circular reference error.
Regarding the circular error, you may be trying to apply the formula to the cell you are already in. For example, if you are trying to apply the formula A1 / 127 - 1 in the cell A1 Excel won't know what to do because you have specified that the value of A1 is both the value in the specified cell and another value ( A1 / 127 - 1), which can't be true.
Now, the only way I know of to do what you're requesting is with VBA, because I realized just now that I asked a very similar question a while ago which was helpfully answered by Gary. The code was as follows:
Sub Formulate()
Dim N As Long, i As Long, dq As String
N = Cells(Rows.Count, "A").End(xlUp).Row
dq = Chr(34)
For i = 1 To N
v = Cells(i, 1).Value
Cells(i, 1).Formula = "=Text(" & v & "," & dq & "mm/dd/yyyy" & dq & ")"
Next i
End Sub
Simply - if any cell in Column B contains thisvalue then append to the adjoining cell in Column A with sometext.
How is this done?
A simple if statement. For example:
=IF(ISNUMBER(SEARCH(thisvalue, B1)), sometext, "")
EDIT: The ISNUMBER(SEARCH(thisvalue, B1)) searches for thisvalue in B1, and if it finds it, it returns a number (that number being the starting index of thisvalue within B1).
EDIT #2: To append the inserted value to the end of the current value in cell A, use the CONCATENATE formula.
Example:
=CONCATENATE(A1, sometext)
Put this formula in A1, then drag down as necessary:
=IF(B1="thisvalue","sometext","")
EDIT
Using a the Visual Basic Editor, you can update the contents of cell A like this:
Private Sub UpdateColumnA()
Dim x As Long
For x = 1 To 65536
If InStr(1, Sheet1.Range("$B$" & x), "thisvalue") > 0 Then
Sheet1.Range("$A$" & x) = Sheet1.Range("$A$" & x) & "sometext"
End If
Next
End Sub
Repeated runnings of the macro, however, will append the text again; you'll need more validation code if you don't want this to happen.
copy-paste in A1 , considering that you have values in B
=IF(ISNA(VLOOKUP("thisvalue",B:B,1,FALSE)),"",VLOOKUP("thisvalue",B:B,1,FALSE)&"ADDITIONAL VALUE")
it is saying:
if value of vlookup is is empty (if lookup returns nothing) , then show empty value ( double quotes)
but if the value of lookup returns something, then do this lookup and append "ADDITIONAL VALUE" text to found result
I think I have what you are looking for, let me know if you are still interested and if you want me to elaborate further. This formula in cell F2: =IF(ISNUMBER(SEARCH($U$2,E:E)),$V$2,"")&IF(ISNUMBER(SEARCH($U$3,E:E)),$V$3,"")&...
where you are searching for a value that you specify in U2 across all cells in column E:E, if it finds a match it appends the value you specify in V2. To search for multiple words assigning corresponding value simply concatenate as shown as much as you like. I am able to specify hundreds of words (and corresponding values). I hope it helps.
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?
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
Select the cell you want to be like this,
Go To Cell Properties (or CTRL 1)
under Number tab
in custom
enter
"X"#
Select the cell you want to be like this, go to cell properties (or CTRL 1) under Number tab in custom enter "X"#
Put a space between " and # if needed
Select the cell you want,
Go To Format Cells (or CTRL+1),
Select the "custom" Tab, enter your required format like : "X"#
use a space if needed.
for example, I needed to insert the word "Hours" beside my numbers and used this format : # "hours"
Enter the function of = CONCATENATE("X",A1) in one cell other than A say D
Click the Cell D1, and drag the fill handle across the range that you want to fill.All the cells should have been added the specific prefix text.
You can see the changes made to the repective cells.
Option 1:
select the cell(s), under formatting/number/custom formatting, type in
"BOB" General
now you have a prefix "BOB" next to numbers, dates, booleans, but not next to TEXTs
Option2:
As before, but use the following format
_ "BOB" #_
now you have a prefix BOB, this works even if the cell contained text
Cheers, Sudhi
Michael.. if its just for formatting then you can format the cell to append any value.
Just right click and select Format Cell on the context menu, select custom and then specify type as you wish... for above example it would be X0. Here 'X' is the prefix and 0 is the numeric after.
Hope this helps..
Cheers...
Go to Format Cells - Custom. Type the required format into the list first. To prefix "0" before the text characters in an Excel column, use the Format 0####. Remember, use the character "#" equal to the maximum number of digits in a cell of that column. For e.g., if there are 4 cells in a column with the entries - 123, 333, 5665, 7 - use the formula 0####. Reason - A single # refers to reference of just one digit.
Another way to do this:
Put your prefix in one column say column A in excel
Put the values to which you want to add prefix in another column say column B in excel
In Column C, use this formula;
"C1=A1&B1"
Copy all the values in column C and paste it again in the same selection but as values only.
Type a value in one cell (EX:B4 CELL). For temporary use this formula in other cell (once done delete it). =CONCAT(XY,B4) . click and drag till the value you need. Copy the whole column and right click paste only values (second option).
I tried and it's working as expected.