Search cell for text and add if not found - excel

I have a product spreadsheet that contains a row with file names of images. Some have the file extension and some don't. I am trying to figure out a way to avoid adding ".jpg" to an entire column of cells in my excel worksheet. Is there a method that can help me search to see if the specified filename in the cell is already ending with .jpg? At the same time is it possible to add .jpg if its not there? I have tried with Concatenate and IF statement, but I am not having any luck.
Is there a function or method that can search if my cell contains the file extension(.jpg to be specific) and if nothing specified, is it possible to add one such as ".jpg"?

I created the following spreadsheet, as you can see some of the values have the extension ".jpg" and some don't
A
1 one.jpg
2 two
3 three.jpg
4 four.jpg
5 five
6 six
7 seven.jpg
8 eight
9 nine.jpg
I am assuming that you meant you had a spreadsheet similar to the sample I typed here, with more entries
I google for a way to read the last 4 characters of a cell in excel, this gave me the =RIGHT(A1, 4), this means that wherever you type this formula you will get the last four characters of A1
So using IF + RIGHT + CONCATENATE I was able to read the values in the A column
If the last 4 characters in the A1 are the same as the string ".jpg" then just give me back the value of A1, if the last 4 character of A1 are NOT the same as the string ".jpg" then give me back the concatenation of A1 and the string ".jpg"
the formula is as follows
=IF(RIGHT(A1,4)=".jpg",A1,CONCATENATE(A1,".jpg"))
instead of using the string ".jpg" you can type the string in a cell and use the cell number.
I have this formula in column E, I first wrote in E1, I then copied it to the rest of the cells in column E, this means that a copy of column A is being created, I do not know if the formula can be changed so that the formula searches the cell/column where it is written.
I hope this is of some help, and if you see any errors, or know of a better way to do this feel free to correct/share, as I myself am learning
Good luck

I'm assuming you want to solve this using worksheet functions rather than VBA code, I would use some variation of the following:
=IF(RIGHT(A1, 4)=".jpg", A1, A1&".jpg")
This formula looks at cell A1 and adds .jpg to it if it doesn't already end in .jpg
I can't guess how to integrate it into your sheet but should give you a good start

Related

How to tell if a cell exists on another Google Sheet

I have 12 sheets in one Google Sheets document labeled for each month (January - December). On each sheet column A contains a project number, e.g. "6091".
I'm trying to find a function that will check all of the other sheets to see if there are duplicate cells in the "project number" column of other sheets.
So: "Do any of the cells in column A, match any of the cells in column A on other sheets".
Is there a quick way to do this?
The formula =arrayformula(iferror(match(A2:A, AnotherSheet!A2:A, 0))) checks each value in A2:A of the present sheet for being in A2:A of AnotherSheet. If it's there, it returns the position in AnotherSheet, otherwise the output is empty (the error #N/A is suppressed by iferror).
You can use the above for each of the sheets separately. Alternatively, if you are not interested in the positions and just want to know which entries from A2:A are found elsewhere, then add the results for each sheet:
=arrayformula(iferror(match(A2:A, AnotherSheet!A2:A, 0)) + iferror(match(A2:A, ThirdSheet!A2:A, 0)))
The output is 0 is there is no match, and a nonzero number if there is.
You may try using this to find the number of duplicates:
=counta('JAN'!A:A,'FEB'!A:A)-countA(unique({'JAN'!A:A;'FEB'!A:A})
Where A:A is your column for the data you want to check and the respective files.
This formula counts the total number of data you have, minus the unique data, therefore giving you the total number of duplicates in your dataset.
This formula gives you an overview of the total number of duplicates, however, it doesn't show which cell is a duplicate.
Alternatively, you can add a checker column and input the following formula to check if that specific cell is a duplicate.
=match(cell to check,{range 1;range 2;...range 12})
Alternatively, you may use this formula to find the exact duplicates between the ranges, however this formula does not search within the range itself for duplicates.
=arrayformula(filter(range to check,(countif(arrayformula({Range 1;range 2}),{range to check}))>1))
Personally I think that the last option would be the best as it gives you the exact data to correct.
I am still new to this so hope this helps:)
This formula should work for numerical values:
=COUNT(QUERY({March!A:A;April!A:A},"where Col1="&A2))
If you are searching for text values it would be
=COUNTA(QUERY({March!A:A;April!A:A},"where Col1='"&A2&"'"))
Unfortunately the QUERY function does not work within an arrayformula so you would need to copy the formula down the column. You can add in extra sheets into the { } array as required, separated by a semi-colon
Edit: actually, borrowing from #sandwich, this version should work without the need to copy the formula down the column:
=arrayformula(iferror(match(A2:A,{March!A:A;April!A:A},0)))

Excel: How to copy specific cell data (zip codes) into a new column

I have two columns of cells that have irregularly formatted addresses.
I need:
1) just the zip codes to be copied into a new column;
2) the rows that do not contain zip codes to be either highlighted or empty so that I can easily identify which ones are missing.
This seems like it would be simple to do, but I can't figure out how to have Excel just find all instances of 5 consecutive numbers. Currently they are formatted as text so that the zero's are displayed. Any help greatly appreciated.
Here's what it would be to start with:
Here's what it would look like when done (highlighting optional):
You don't have Regular Expression in normal Excel. You would have to go into VBA to do that. However, for your case, there's an easy pattern: notice how the zip code is after the last space, and it's always 5 digits long? The challenge then become finding the index of this last space and extract the 5 characters that follow it. It will be clearer if you split them into 2 formula
// C3 (index of last space character):
=FIND("|",SUBSTITUTE(B3," ","|",LEN(B3)-LEN(SUBSTITUTE(B3," ",""))))
// D3, the 5 characters after that.
// Return an empty string if the address doesn't match the pattern
=IFERROR(MID(B3,C3+1,5),"")
Another approach to what Zoff Dino wrote is to break it out a bit as shown below:
In cell C3 enter the formula you see in the formula bar
Drag that down the row set and over 1 column (so it runs for column B as well)
In column use this formula: =IF(AND(C3="",D3=""),"",IF(C3="",D3,C3)) and drag it down.
This will account for all possible situations you have shown and not error out on you (unless other patterns emerge).
You can then use conditional formatting to highlight the rows with no zip code as shown in the picture:

Excel Formula finding numbers in column?

I have a column filled with numbers. Some rows have more than one number and are separated by and underscore '_'. I am trying to create a formula that will check to make sure all numbers in a range - say 1 through 300 are in the column. But, everything I come up with is finding the number even if it is in another one. For example, I am searching for 5 which I know is missing, but the row with 251 matches for the 5.
A sample section of the column:
20_21_22_23_30_130_131_185
20_21_22_23_157_185_233_234_245_246
24_40
24_40_41
24_40_343
28_76
28_254_255
30_44_130_131_226_342
30_76_145_193_224
30_130_131_185_226_245_246_317
31_32_33_35_36_43_44_45
31_32_33_35_36_126_127_128_130_131_187_226
I have a couple hundred rows and need to make sure I have all number listed.
Any suggestions would be helpful.
Thanks!
change your formula to instead of looking for number in string to look for "number" as this is your natural delimiter. or if you get your feed your numbers from any other particular column, let say from B2 onwards, change it in formula to "_" & B2 & "_"
EDIT
as pointed out, this solution will miss the numbers if they are they appear first in the cell. two possibilities there, please bear in mind i am not sure on exact formula you use, and the volumne of cells you go through, one option is to feed in the column with preceding "_" and enter formula as array, but this will somewhat slow down the calculation, another solution is to add a formula next to the original range which will be populate with a formula ="_"&B2and populated down and do the search from this column instead

Edit IF statement using filenames in a column

I have a column with filenames:
Excel1.xlsx
Excel2.xlsx
Excel3.xlsx
etc
etc
etc
and I also have this IF statement:
=IF('[MainExcel.xlsx]Data'!$C$4='[Excel1.xlsx]Data'!$C$4,IF('[MainExcel.xlsx]Data'!$E$4='[Excel1.xlsx]Data'!$E$4,7,IF('[Excel1.xlsx]Data'!$C$4>'[Excel1.xlsx]Data'!$E$4,5,0)))
So I am trying to comparate an Excel Worksheet (Data) from all these files (Excel1, Excel2, Excel3, etc) with a main Excel (MainExcel)
Any way of doing this without having to change the IF statement one by one in every row?
Thanks in advanced!
Use a combination of concatenate and indirect.
Since I don't know the full layout of your sheet I won't get too in depth but, for example
=IF(INDIRECT(CONATENATE("[",A1,"]Data'!$C$4"))=4,TRUE,FALSE)
where A1 is the cell that has the name of the other excel file.
You can use the INDIRECT function to build references to other workbooks, using cell references.
As an example, that you can build upon.
Assume:
Excel1.xlsx -> Excel3.xlsx respectively have the values 1, 2, 3 in
cell A1 on Sheet1,
All workbooks are open (or else we would have to add path information
that the file names were in column A
The following entries in column B would pull the appropriate values from the referenced workbooks.
=INDIRECT("'["&A1&"]Sheet1'!A1")
Just using what others have said, assuming that the cell containing the first workbook name "Excel1.xlsx" is in cell A1, then try:
=IF(Data!$C$4=INDIRECT("["&A1&"]Data!$C$4"),IF(Data!$E$4=INDIRECT("["&A1&"]Data!$E$4"),7,IF(INDIRECT("["&A1&"]Data!$C$4")>INDIRECT("["&A1&"]Data!$E$4"),5,0)))
Also, I note that it appears that the case in which the first comparison is false is not covered under your subsequent values (your function just returns the value "false").

Keyword Searches

I have a project where I am given a large amount of information and a description of what issues I am handling. I would like to create a cell at the end of the row that would return yes or no after it performs a search across a row for a specific keyword or piece of text. I have tried using the if(Search()) function, but it only allows for one cell in the row to be searched for the keyword. This would work, but the Keyword(s) that I'm searching for may appear in different columns of the row. Is there anyway that I can create a formula to search the entire row for specific texts? And if any instance of a list of keywords that I have put into the formula appear, can it result in a customizable text response (Yes or no)?
Thanks.
Say in the first row we want to know if we can find "happiness" anywhere in A1 thru C1. In D1 enter:
=IF(ISERROR(SEARCH("Happiness",A1 & B1 & C1)),"No","Yes")
If you have more cells, just increase the concatenation.
you can use COUNTIF to locate a piece of text -any result greater than 0 means the text has been found
use =COUNTIF(A1:F4,"Your Text") if you have to have a full cell match
use =COUNTIF(A1:F4,"*Your Text*") if you want a partial match (e.g. "Dog" will match "CatDog" and "Dogma")
Wrap this in an IF statement to get your desired response
=IF(COUNTIF(A1:F4,"*" & G1 & "*")>0,"Yes","No")

Resources