excel concatenate prefix in comma separated cell - excel

I am horrible with excel. I rarely have to use it but today I do.
I have cells that have images that are comma separated. these cells are in the same column. i need to add a prefix lg_ to each comma separated image in the cell. I have done some reading on concatenate in excel and I am not sure if this is the right method to use. Does anyone have any good tricks/tips to accomplish this?
It currently looks like :
b3f9e6_1008a.jpg,4f57dc_1008d.jpg,9205eb_1008b.jpg,cb1c14_1008.JPG,ad8884_1008c.jpg
the result would look like this:
lg_75c552_599d.jpg,lg_a3a180_599a.jpg,lg_5c2ec4_599e.jpg,lg_dbb052_599b.jpg,lg_419420_599f.jpg,lg_8eb065_599c.jpg
note: images names are different because I just pasted what I already completed manually.

This should be on SuperUser.
What I would do is do Find..Replace on the comma and replace it with ",lg_" (without quotes). Then you need to prepend the strings with "lg_". You can do this by using another column and doing ="lg_"&A1 where you replace A1 with the proper cell reference. Drag this formula down and then copy and paste value that over the initial data.
Edit: Just because you seem new to Excel: To do Find..Replace hit Ctrl + H. The dialog box that will pop up is self explanatory.

This can also be done using the SUBSTITUTE command in a cell formula.
e.g.
Set C30 = "lg_"
Set D30 = "b3f9e6_1008a.jpg,4f57dc_1008d.jpg"
then in E30 type the following: =C30&SUBSTITUTE(D30,",",","&C30)
This does the same as ApplePie's answer, but with the added benefits that you do not need to do a manual replace, and "lg_" is not hard-coded so it can change depending upon the contents of a cell. Therefore you can copy the formula down a column and use different prefixes for each row. e.g.
IF C30="244" and D30="91,99" then E30 = "24491,24499"
IF C31="376" and D31="5,6,7" then E31 = "3765,3766,3767"

Related

Excel noob needs help Replacing a mid value with a different value using excel formula

I'm new to StackOverflow and to Excel formulas!
I'm trying to replace the word "GIL64000" with the word "GIB64000", I need to do this across many cells A2: H6; A9: G13, etc.
The cells themselves contain information as follows: "GIL64000_XX_X" with "XX" varying between WH, BL,OR,PU, etc and the"_X" ranging from L, M, S, XL, XXL (shirt sizes).
So I have cells with values like: "GIL64000_OR_S" , "GIL64000_BL_XXL" , "GIL64000_MIN_M" , "GIL64000_MIN_L" etc.
I've tried to get the replace function working by doing this: =REPLACE("GIL64000";3;1; "B")
But it only does this within the cell I have the formula in.
I've tried to add A2: H6 to the formula, but it doesn't accept it and returns with #VALUE! error: =REPLACE(A2:H6;3;1;"B")
I tried some other string like "MID" function, but I can't figure out how to use MID with REPLACE: =REPLACE(MID(A2: H6;3;1; "B"))
I tried to follow some guides and I still can't seem to get it working.
In essence, what I Want is the word "GIL64000" with word "GIB64000" across all my cells and to be able to change the formula as I need it in the future for other values not only "GIL64000"
The REPLACE command only takes in one reference of the cell, and not a range.
Only Change which you need to make is =REPLACE(A2;3;1;"B"), and then just copy the formula (i.e. Ctrl + C, and Ctrl + V on the other cells where you want to change this).
Also, this cannot be applied on the cell itself but would be applied on an adjacent cell.
Let me know if this helps.
There is also the substitute() function which will work, have shown 2 variations - both will drag down, but the second allows customizing the characters to replace. You could put $ on the B3 and C3 for an absolute reference.
See:
Note: I did not just look for "B" although you could - it depends what other data is there...
I know you said you want a formula, but in this case, don't sneeze at the idea of using a CTRL+H. This looks like the perfect scenario for one.

Change part of excel formula with a constant value

I have an excel formula across a column for which the base changes every "x" number of rows. Note this "x" is not constant and keeps changing. e.g.
=D1/SUM(D$1:D$4)
=D2/SUM(D$1:D$4)
=D3/SUM(D$1:D$4)
=D4/SUM(D$1:D$4)
=D5/SUM(D$5:D$9)
=D6/SUM(D$5:D$9)
=D7/SUM(D$5:D$9)
=D8/SUM(D$5:D$9)
=D9/SUM(D$5:D$9)
I am trying to change the first part of the formulas without changing the second and vice versa. e.g. changing the numerator by 10 cells.
=D11/SUM(D$1:D$4)
=D12/SUM(D$1:D$4)
=D13/SUM(D$1:D$4)
=D14/SUM(D$1:D$4)
=D15/SUM(D$5:D$9)
=D16/SUM(D$5:D$9)
=D17/SUM(D$5:D$9)
=D18/SUM(D$5:D$9)
=D19/SUM(D$5:D$9)
or, changing the base by 100. e.g.
=D1/SUM(D$100:D$104)
=D2/SUM(D$100:D$104)
=D3/SUM(D$100:D$104)
=D4/SUM(D$100:D$104)
=D5/SUM(D$105:D$109)
=D6/SUM(D$105:D$109)
=D7/SUM(D$105:D$109)
=D8/SUM(D$105:D$109)
=D9/SUM(D$105:D$109)
Sometimes, both. Any guidance on how this can be possible?
Thank you.
the first part of this problem seems easy unless I am missing something?
Part 1:
Since the denominator is already in $x form, you can select and COPY the whole range of formulas and PASTE them 10 rows down and then CUT and paste it back into position. The COPY will update the numerators appropriately and when you CUT and PASTE it back into position they will now be just as you want? The second question will be a bit more of a challenge!
Part 2:
OK without VBA I can only think of a really long-winded way to change your demoninators, but I just checked that it does work:
To change the bottom.
Search and replace = with '=
Now you can edit the formulas more freely.
Search and replace D with D%
Search and replace D%$ with D
Search and replace D% with D$
get rid of the '= by using the Data>text to columns option
Now use the copy and paste, cut paste trick from part 1.
Then if you still need your $s back as they were you essentially repeat 1 to 5 again.
Sorry, this looks really long-winded, but if you are desperate and back up before you start it should work.
An excel formula can't replace another cells excel formula... One approach is to make the formula into text and then transform it by other formulas. When transformation is done, you could paste the formula back.
So for changing the D1 -> D11, I would build a dummy series (column K) then write a formula (cell L1). Then I can copy the formula and paste it into the correct column.
Replaceing the "=", with a special character and then you can transform the formulas.
(Column F).
In Column I, the formula used is: =RIGHT(F1,LEN(F1)-FIND("/",F1))
For changing D$1 -> D$100, I think I just would copy and replace it by searching in "Formulas".
This approach can be feasible for acouple of hundred cells. If the list is very long, I would recommend some VBA solution, where you can grab a cells formula with .Range("A1").Formula

Excel change strings in formulas while copying

I have a cell number as a string ("A1") in a formula, and this needs to be changed relatively while copying, like it does automatically to normal cell references. so I don't have to visit 400 cells and change them all by hand.
Any way I can manage this? Thanks for the help.
Formula I am using in 400 cells:
=IF(IDENTIC($M$10;"Entries are correct.");IF(ISNUMBER(FIND("A1";$N$5));"S1";IF(ISNUMBER(FIND("A1";$N$6));"S2";IF(ISNUMBER(FIND("A1";$N$7));"S3";IF(ISNUMBER(FIND("A";$N$8));"S4";IF(ISNUMBER(FINDEN("A1";$N$9));"S5";"")))));"")
I don't want to change every single cell as text in all 400 cells, it should change relatively as normal cell references do.
To get a cell reference as a string in Excel you can use the CELL function:
=CELL("address";A1)
Since the second parameter to the function is an actual cell reference, if you copy and paste this formula it will auto-update accordingly.
Bear in mind this will return a string containing an absolute address so it will return "$A$1", not "A1".
CELL(...) will work.
More generally, you can also build the formula as strings using concatenations. This can be useful when you have a list of stuff and you would like to have formulas that refer to those names. Or in your case it would also work.
Building the formula as string with concats & then search & replace
First I build up as much as I can the formula so that the general structure is already formed (only the reference you'll want to change will not be final):
Using your case as an example:
Then, I wrap that nearly-formed formula into a CONCATENATE(). I then arrange things to have a references that I will point to within that CONCAT() that will auto-increment to the text I actually want to include in my formula. Something like this:
=CONCATENATE("IF(FIND(""",A1,"""$A$4),TRUE, FALSE)")
The ,A1, refers to the actual cell, so that cell's content is what will be included in my formula. You can then increment this all the way to build the proper formula for each cell (the 400 ones in your case). You need the triple """ because you want to actually include A1, B1 etc... are text references, not cells.
Then, all you need to do is selected all those formulas, copy them & make sure to choose past as values, say the line under (to keep you concatenate intact so you can edit it later if needed). Then with that pasted line all selected, you use a find & replace to add an "=" sign to the beginning of formulas. Better be too specific on the find & replace, so find "IF(F" and replace by "=IF(F" or similar. Then magic happens:
You can see that A1, C1, D1 have returned TRUE while the rest are #VALUE! because the find method has failed to find the string.

Concatenate repeats first row cell values even though formula selects different cells

I am trying to prep some zip codes to go into the WHERE clause of a SQL query:
WHERE [Zip_code] IN ()
To do this I put all the values into Excel and want to concatenate the zip codes with an apostrophe at the beginning and an apostrophe, a comma, and a space at the end so 99508 would become '99508', . So I wrote the equation
=Concatenate("'",D2,"', ") where D2 is the zipcode. It worked for the top row producing '99058', but when I filled down it still showed the value for D2
To make matters more confusing, when I click on the cells and see the formulas, they are tracking the proper cells but still show data for the top row
I have tried everything that I can think of to solve the problem: reformatting everything as text, formatting the zipcodes as Numbers rather than text, putting the text in the adjoining columns (C2 has an apostrophe, D2 has the Zip code, E2 has apostrophe, comma, and space) and concatenating, using & instead of concatenate ("'"&D2&"', " ), concatenating A on the front and B on the end to do a find and replace, but I still get the same result. If I select a concatenated cell, click on the formula bar, and press enter the cell shows the proper concatenation, but I would rather not do that for every single cell.
My co-worker suggests including that the zip codes were taken from pivot table outputs.
Any suggestions?
Turns out that calculations had somehow been set to manual instead of automatic.
Switching back to automatic solved the problem.
use this instead
=concatenate("'";D2;"',")
idk if gonna work on you sheet, bc i have in spanish my MS-office suite
but if doesn't work, replace the ; for ,
if you copy the formula to the other cells, this must change to the next row
First is clear the worksheet format
secondly, click on file on the excel, then to option, to formula after formula, check the position of the calculation. if its in automatic change it back to Manual and then change it back to automatic. That will solve it.

Any way to copy/paste formulas in a range of cells but keep absolute?

I have a matrix of data and each cell is a formula. All cell formulas are relative, so when I copy and paste just below, the formulas are now off.
Here's what I know works:
Change each cell's formula from relative to absolute
Copy the text from each formula, then paste this text below
I don't want to go and F4 each part of every formula for dozens of cells. Is there a way to copy paste a large batch but tell Excel to keep the exact formulas as written?
I personally do a bulk Find and Replace on the original range, replacing all "=" signs with a random text string which is guaranteed to not occur anywhere within those formulas, my usual choice being "##".
This converts all the formulas to text strings, after which you can paste the range before then performing the reverse Find and Replace, i.e. replacing "##" with "=", which coerces Excel into treating the strings as actual formulas once more.
Of course, if we're talking about a very large amount of formulas, i.e. several thousand, then this operation can take a while to perform, since not only is Excel required to carry out the Find and Replace on all strings, but also to calculate all the newly-created formulas.
Regards
When pasting, right click and choose "Paste Special" and use "Paste Formulas" (the fx icon).
Edit: Ah, I realize now this only works for 'fully anchored' ($A$1) cell references.

Resources