Excel Nested IF Function with AND/OR - excel

I have tied quite a few combinations of the AND/OR functions and have had no luck.
Here is what I need to create:
In column B, I have Firm ID's, which range from two numeric characters to six numeric characters.
I need every the letter "I" and a certain number of zeros before each Firm ID in column B.
-So if the Firm ID has two numbers, I need to add "I0000" to the left of the Firms ID in column B. So the end result would be "I0000##", totalling seven characters.
-If the Firm ID has three numbers, I need to add "I000" to the left of the Firms ID in column B, So the end result would be "I000###", totalling seven characters.
-and so on and so fourth for 4,5, and 6 character firm ID's (The Largest firm ID I have is 6 characters, so it would only need the letter "I" added)
I was trying to use something along these lines =if(len(b2=6),concatenate("I",B2),IF(len(b2=5),concatenate("I0",B2),If(Len---------you get the idea. It wasn't pretty, and it only added an "I" to all my Firm ID's.
I realize that it will require the use of either an OR( or AND( function. I tried to write it to no avail. I am a visual learner, and don't mean to troll anyone reading this, but if its not to much trouble it would really help me to see the actual function written out, so I can compare it to my incorrect function and see my mistakes.
Just pointing me to an excel training site about AND/OR functions will not help me.

For a formula solution, you could use the TEXT function:
=TEXT(B2,"I000000")
Alternately, you could select column B, right-click -> format cells -> Custom -> type I000000 -> OK

Doing a custom format for cells in column B should do the trick, with no coding / functions needed. Choose the cells you want to change, right click, go to format cells. From there choose the Number tab, and choose the Custom category. You could do something like "I"000000 in the box under "Type".

Related

How to count the number of occurances of values in a cell based on 2 different critera

I am trying to count (or rather to ascribe the number of total orders) of customers based on a) whether they have purchased before, and b) the date of each purchase.
The table also contains all the products ordered in a single order, each in a different line.
Column F is what I'm trying to define (I have filled these numbers in manually and highlighted for clarity).
I am trying to use COUNTIFS:
=COUNTIFS($B$2:$B3,$B3,$A$2:$A3,$A3)
However, I cannot make it work properly.
I need it to count only if
a) the entry in column B is the same as the previous entry, and
b)the date entry (column A) is different then the previous entry. Otherwise, column F should return the same value as the previous entry (so that all 'total orders' for the same email with the same date have the same total orders number.
I think I'm likely missing an 'else' statement somewhere.
Any help is greatly appreciated!
Try this formula:
=IF(B2=B1,IF(A2=A1,D1,D1+1),COUNTIFS(A$2:$A2,A2,B$2:$B2,B2))
Tested below.
In English, the formula checks if emails are equal, then if dates are equal, if so, it grabs value from above. If dates are not equal but emails are it adds one to number from above. If emails are not equal, it starts the count anew with your original COUNTIFS. Because it will always generate a 1 for first row, the structure of the IF blocks work.
I think this would work for you:
=COUNT($A2)+COUNTIFS($A$2:$A2,"<>" & $A2,$B$2:$B2,"=" & $B2)
you can add in operators inside ""s and 'concatenate' with an ampersand (&)
This formula will count any entry above the date given, as long as it is a different date and the same email. I know this is what you were asking for, but it isn't neccesarily accurate as a count of prior purchases. In order for this to be accurate you should consider a different method for recording multiple product purchases on the same date. Otherwise, just label the column "Qty of prior products purchased" as opposed to "Qty of prior purchases. :D GL, speak up if you need anything else!

Excel SUMIFS which adds values if column a, or column b contains a specified value

I've had a look around and can't find a solution, and I don't even know if this is possible.
I have two worksheets. I would like Sheet1!G5 to display the sum of values in Sheet2!D:D where Sheet2!A:A OR Sheet2!B:B is equal to Sheet1!D5.
I know its a bit complex, and like I say I don't even know if it is possible, or if SUMIFS is the correct formula to be using.
see images below for dummy data in the spreadsheets..
basically I want someone to be able to search how many Desktop or how many HP Elitedesk 800 G1 there are (there are more different models of desktops, laptops and monitors etc, but I just don't have them in the dummy data...that's why I want to be able to search both fields.
If my logic is correct you should be able to get away with two separate SUMIF's, one for column A and one for column B, added together:-
=SUMIF(Sheet2!A:A,D5,Sheet2!D:D)+SUMIF(Sheet2!B:B,D5,Sheet2!D:D)
It doesn't look as if it's possible to have the same thing in column A and B for any row, but if so you could make a correction to avoid double-counting as follows:-
=SUMIF(Sheet2!A:A,D5,Sheet2!D:D)+SUMIF(Sheet2!B:B,D5,Sheet2!D:D)-SUMIFS(Sheet2!D:D,Sheet2!A:A,D5,Sheet2!B:B,D5)
The first formula can easily be modified to work with more than two criteria columns (e.g. if you wanted to match on serial number as well), but the second one can't.
To get the total quantity based on more than two columns, where a string can occur more than once in the same row, you would need an array formula like
=SUM(SIGN((Sheet2!A2:A10=D5)+(Sheet2!B2:B10=D5)+(Sheet2!C2:C10=D5))*Sheet2!D2:D10)
which must be entered with CtrlShiftEnter

Using VLOOKUP or INDEX/MATCH to run a Lottery

I'm using Excel to run a sort of lottery.
The spreadsheet columns are set up thus:
COL1:Person Name; COL2: Chosen Number A; COL3: Chosen Number B; COL4: Chosen Number C
There is then a set of data, generated using RAND() and ROUND, that gives 3 winning numbers, each between 0 and 10.
What I'm trying to do is identify a winner, by using VLOOKUP or INDEX/MATCH, or some combination, or other function, to identify the winning person, so that there is a single cell that returns the name of the winner.
The added complexity is that by looking up each of the numbers individually by column, an individual selection of, say, 1,4,8, isn't a winning selection against a randomly selection of say, 4,8,1.
Ideas?
You can concatenate numbers to additionalcolumn so it will contain string "1,4,8," and then perform a VLOOKUP for concatenated in the same way winning numbers.
By the way, this solution will show only first person, but isn't it possible that several persons guessed same numbers and won?
If you want to generate a 3-digit number, by far the easiest thing to do is to use the formula
=RANDBETWEEN(0,999)
You can select the cells and then enter (via the format dialog accessible by right-clicking) the custom format 000 if you want it to display as 3 digits so that e.g. 7 displays as 007. This will allow you to directly use VLOOKUP on a single value. #kipar asks an excellent question about potential multiple winners.
I implemented the abovementioned solution and it was quite easy. After your 4 columns, you add one column with
=TEXT(B1;0)&TEXT(C1;0)&TEXT(D1;0)
which combines the number to one string. Then you put your winning number in a cell of preference mine was M28 and the value was 123. After your first five columns you use the following formula.
=IF.ERROR(INDEX(A$1:A$4;SMALL(IF(E$1:E$4=TEXT($M$28;0);ROW(E$1:E$4));RI-OW());1);"")
The IF.ERROR is used to put a blank when there are no multiple winners. The index is used to get the winners out of your first column, that'w why there's a one at the end. The small is used to find the first occurence of the winner. You also have to enter it as an array formula so press ctrl+shift+enter instead of just enter when the formula is completed. I hope this answer is satisfying.
PS. For extra information on the use of this function go here: http://chandoo.org/wp/2014/12/09/multiple-occurrences-lookup-and-extraction/

Excel Search and Replace string with vlookup

I have a excel sheet where I have columns that say
"I like TSX but I prefer 350"
"I like beamer but I am fan of S-Class"
I want to replace this with
"I like Acura but I prefer BMW"
"I like BMW but I am fan of Mercedes"
I have another excel sheet with the match and replace values. For example
TSX, Acura
TL, Acura
350 BMW
Beamer, BMW
etc.
I know how to use vlookup, but this is way advance for me. Any help? Thanks you.
Rather than use vlookup at all, if you don't have many types of cars you could simply use SUBSTITUTE. Works as
=SUBSTITUTE(A1, "TSX", "ACURA")
Then wrap it many times, once for each possibility:
=SUBSTITUTE(SUBSTITUTE(A1, "TSX", "ACURA"),"S-CLASS", "MERCEDES"))
If you have many possibilities, this will either need 2 helper columns, or vba. Let me know if that's the case. Basically without vba you will need to search for the first term in 1 column, then put the 2nd term in the second formula, then replace the 1st term with a vlookup'd equivilent, then replace the 2nd term with a vlookuo'd equivilent (using substitute as above).
Edit
Reading the q again it seems there are many possibilities, so we will need to use two helper columns and areay formulas to solve. VBA is likely better, but In on my phone so cant error test anything, and you might not want vba anyway.
The principle for these helper columns is going to be to find which 2 vehicles exist in the text. Once you know which two exist, you can simply replace both as above.
The first stage of the formula we will be putting in colns B and C, (assuming your 'vlookup text' is in columns A and B on sheet2 from rows 1 to 100) is:
=If(iserror(search($A1,sheet2!$A$1:$A100)),"",row(sheet2!$A$1:$A$100))
This is an array formula, which works on each cell in the range you give it. To confirm it, press CTRL + SHIFT + ENTER instead of just ENTER. It gives you an array of results, that you need to collapse into a single answer. so in column B, wrap it in a MIN function. For column C, wrap it in a Max function.
So now column B shows the row number of 1 matching term, and row C shows the row number of the 2nd matching term.
So now in column D, we know the row number of the first match, the first replacement term, and thend match and replacement term. Replace everything as follows:
=Substitute(substitute(A1,INDEX(SHEET2!$A$1:$A$100, B1),INDEX(SHEET2!$B$1:$B$100, C1)),INDEX(SHEET2!$A$1:$A$100, C1),INDEX(SHEET2!$B$1:$B$100, B1)))
Make sure you confirm with CTRL SHIFT ENTER instead of just enter.
Apologies if this isnt formatted 100%; Im on my phone and will error check it later if it causes problems. Let me know if you have questions about how this works.

Excel equation needed; if any phone number matches check to make sure names match in other column

I work at a Federal Prison. I have a spreadsheet that shows every inmates call with thier name and number they called. I want to write an equation that will find duplicate phone numbers and if the duplicates have <> (not equal) names I want it highlighted or printed on a new tab or something.
Right now I have about 3K rows of calls. I do a conditional formating to highlight the duplicate numbers, I sort biggest to smallest and then I look down this long sheet confirming the inmate names match. It takes way too long.
I want a tab that automaticly displays:
Johnson (123)456-7890
Smith (123)456-7890
This will show me that in a duplicate phone number the names did not match.
What do you all think?
Thanks,
Matt.
I suggest a PivotTable with telephone numbers then names for ROWS (and maybe count of either for Σ VALUES). More than one name under any one number should stand out visually without the need for anything more elaborate.

Resources