Appending separators in the formula - excel-formula

Can someone help on this? I have column A with telephone number and Column B with country code. I want to remove the country code in column A if it is there to avoid duplication. Can someone help me?
Column A 1234567 Column B 1 Column C 1234567
Column C should have the formula to check if 1 is already in the beginning of the cell value A, if yes, it'll remove it, but if not, column B value will be added to it. Another scenario is below: Column A 234567 Column B 1 Column C 1234567
Also, I would like to add separators in this formula after the country code, and after three digits of the country code based on column 1 with removed country code in it.
How to append it in this formula?
=IF(B1 = --LEFT(A1, LEN(B1)),A1,--(B1&A1))
Appreciate your answer!

As far as I understand what you describe, you may be after something like this:
="+"&TEXT(B1,"0")&"-"&
IF(LEFT(TEXT(A1,"0"),LEN(TEXT(B1,"0")))=TEXT(B1,"0"),
MID(TEXT(A1,"0"),LEN(TEXT(B1,"0"))+1,99),
A1)
The statement about "after three digits of the country code based on column 1 " is unclear. This formula gives you tools to add characters before and after the country code, while it removes country code duplication.
edit after comments You don't really describe it, at least not clearly, but it looks like you want a vertical bar after the country code and again after the first three digits of the phone number. The formula to achieve that is
=TEXT(B1,"0")&"|"&
REPLACE(IF(LEFT(TEXT(A1,"0"),LEN(TEXT(B1,"0")))=TEXT(B1,"0"),
MID(TEXT(A1,"0"),LEN(TEXT(B1,"0"))+1,99),
A1),4,1,"|")
another edit after stitching together what else you might want but don't clearly describe: If column B can possibly contain either numbers like 1 or 63 but also text that starts with a country code, followed by a space and some other stuff, like 63 2, then you can use this formula
=LEFT(TEXT(B2,"0"),FIND(" ",TEXT(B2,"0")&" ")-1)&"|"&
REPLACE(IF(LEFT(TEXT(A2,"0"),LEN(TEXT(B2,"0")))=TEXT(B2,"0"),
MID(TEXT(A2,"0"),LEN(TEXT(B2,"0"))+1,99),
A2),4,1,"|")

Related

Find items in a list that contain all sub-items

I have two lists as follows, Column A and Column D:
I would like to find all cells in Column A that do not contain a value from Column D.
For instance, A1 should be 0 because it contains the values 'a', 'b', 'c' and 'd' - all of which are in Column D.
A2 should be 1 because it contains the value 'h' - which is not in Column D.
My formula so far is very simple:
=COUNTIF(D1:D7,"*"&$A1&"*")
I'm guessing I could split the values in Column A to check, but am not too sure how.
I would like to avoid any VBA if possible.
Your question is not entirely clear to me, so far as what you want for results under different circumstances.
Your formula will return an array of values, so you need to account for that. The array consists of a 1 or a 0 depending on whether the character matches a letter in the D1:D7 range.
If you want to return the number of letters in your column "A" item that do NOT match an entry in Column "D", then try:
=LEN(A1)-SUMPRODUCT(COUNTIF(A1,"*"&$D$1:$D$7&"*"))
The SUMPRODUCT functions sums the array that the COUNTIF function is returning.
If you want something else, you will need to be more specific.
Cross-tabular layout
Using your logic, just with different layout of the data, you can achieve this:
Formula for B4 is: =COUNTIF(B$3;"*"&$A4&"*")
Formula for B1 is: =B2-SUM(B4:B10)
This is more along the lines of a comment, but I don't have enough reputation yet for comments.
The accepted answer from #ronrosenfeld will not work if the string in Column A contains repeated characters from the list in Column D. For example, if A1 contains "abca," it will return 1 rather than 0 because the array entry for "a" is 1 rather than 2 (it can only be 0 or 1).
So be aware that it only works if the letters are not repeated.
I cobbled a formula together based on some array magic I found by #ronrosenfeld here. (It seems so appropriate that Ron already got credit for answering this question, as my answer is a modification of another of his.)
The following formula works for any length of string in Column A and for any combination of letters including duplicates. It is entered as a regular formula:
=IFERROR(SUMPRODUCT(MATCH(MID(A1,ROW(OFFSET($A$1,,,LEN(A1))),1),D$1:D$7,0)=1),1)
You just enter it in B1, then copy it down as far as you like.
It works for strings of any length. If a cell is blank, it returns 1 because there is nothing there that appears in the list. If you want 0 for a blank cell, you can adjust the formula for that situation. Brute force approach:
=if(isblank(a1),0,IFERROR(SUMPRODUCT(MATCH(MID(A1,ROW(OFFSET($A$1,,,LEN(A1))),1),D$1:D$7,0)=1),1))

How to find a specific text from a column that a set of comma separated values in Excel?

I have a column like this
Now I know the set of values. Like someone was asked about 'Sports' and he/she had the below choices:
Cricket
Tennis
Football
Others
Now the values that you see in any cell of the column apart from 'Cricket', 'Tennis' or 'Football' are entered as 'Others'
So I want the output in this manner that will only fetch what has been put as 'Others' and where it was not chosen it will be '0' (zero)
But if you see I was taking about 'Others' as an example. For this example, there is no such letter as 'Others', instead of there are 'I dont like any sports' or 'Playing sports was good at home' etc which can be anything followed by. So I want to show anything that doesn't match with 'Cricket', 'Football' or 'Tennis'
I'm a very novice at Excel and kind of doing this first time. Can anyone help what formula should I write at the starting of B column?
Enter this as a function in the first row in your B column and pull it down for all your rows:
=IF(A1="Others";A1;0)
If you pull it down correctly, then the row below it should read =IF(A2="Others";A2;0), rinse and repeat for all rows below. All cells in the B column should now either show "Others" or 0.
This is a simple IF statement in Excel and should be read as:
=IF(A1="Others";A1;0)
Or in pseudo-code:
IF A1 EQUALS "Others" THEN B1 EQUALS A1 ELSE B1 EQUALS 0
You can also replace the A1 and 0 in your formula by anything you like, e.g. you can set it to true and false by changing it to =IF(A1="Others";true;false).
I don't know what you are planning to use it for, but you can also just set a filter at the top row, and filter out every cell which does not contain "Others". When working with large Excel-files, filters are your friend.

Comparing 3 cells to a 4th cell. 4th cell has random number of spaces between arguments

Sorry if this is lengthy but I want to be as clear as possible. Here is an example so that its easier to understand, then I will lay out the details, finally I will explain what I would like to do.
A picture of my example is at: imgur.com/9uK9So9
I couldn't post a picture because of <10 rep :/
Column A- the "name" portion of it must be exactly 12 characters and the "number" portion must be 5 (not including the '.').
So, cell A1 is "ADAM2_______25.000".
name="ADAM2_______"
number="25.000"
Column B-just the name portion without any extra spaces.
So, cell B2 is "ADAM2"
Column C-same as column B but may be different (the reason I'm doing the comparison)
Column D-the number portion without the trailing 0's.
So, cell D2 is "25"
Column E is where I want the comparison to output something along the lines of true or false.
I know that columns C and D are correct, I am not sure if A and B are though. I want to compare column A with the values in Column C and D but I do not know how to account for the random number of spaces in between the name and number portion in Column A. Also I want to make sure Column B matches column C but that should be pretty easy once the first part is done.
Basically, how to I account for the varying number of spaces/trailing 0s in my comparison?
Mostly I've been using Conditional IF/AND statements. I tried using the CONCATENATE function but it didn't seem to work as I was hoping.
Thanks!
^^EDIT 1
In column E I tried =IF(A2 = (B2+D2),TRUE(),FALSE()) But obviously that will not work. It gives an #VALUE! error.
I tried splitting Column A into 2 more columns using text to columns. This got rid of the trailing 0s and the extra space(s) after the end of the "name" part. From here I think It should be pretty easy with just basic IF statements.
What you want is the string-searching functions - either FIND [case sensitive] or SEARCH [not case sensitive]. These functions look at a given string, and check to see whether a search term is within that string. If it is present, it gives you the character number where the match starts; if it is not present, it gives an error.
So to see if A2 contains the term in B2 as well as the term in D2, you would use:
=if(and(isnumber(search(B2,A2)),isnumber(search(D2,A2))),"BOTH TERMS PRESENT", "AT LEAST 1 TERM NOT PRESENT")
Note that this doesn't compare with column C at all - I can't tell whether you actually are trying to compare that one are not.

Counting names using three columns - code

Using the following input data, I am trying to extract count for each name's (column D) type.
input example:
the current code, picks up count if column b is unique.
desired output:
RBS = 5, CA = 1, SG = 1,
I found this code and updated it to my requirements. however, I can not get it to output results, for the following condition:
if column B (deal), column C (total) and column A (date) are unique (non-duplicate) then count the name's type as 1 otherwise if both three columns are duplicate, then only count as one.
(Desired Output)
Hope the example above clarifies the logic a little clearer.
Any help on this issue would be very much appreciated.
Kind regards
No need for complex VBA here - a "simple" formula will do:
=SUM(--NOT(ISERROR(SEARCH(C1,Input!$D:$D))))
(This assumes the name of the bank is stored in cell C1)
Please note that you need to enter this as an array formula, i.e. press Ctrl-Shift-Enter!

Find something in column A then show the value of B for that row in Excel 2010

Basically my problem is that I have a string in one cell in excel, I then need to see if that string exists in another row (not one cell but the whole row) and if so then print the contents of another cell in the same row but in another column.
I will give a basic example:
Title Answer
Police 15
Ambulance 20
Fire 89
Now I need to scan the title column for, say, "Police" and then populate the cell with the value under Answer (in this case 15).
I cant just say IF(A2="Police";B2;"" as I need the scan the whole of the Title column.
I have tried using IF(COUNTIF(A$2:A$100;"Police"); which scans the contents of A2 to A100 for the string Police, and know how to make it print a constant (just put something after the ;) but cant work out how to make that "constant" a variable that changes depending on the found row. So if the COUNTIF found Police in cell A44 then the answer to my formula would be B44, the same as if it found Police in A62 then my formula should show B62
I hope this makes sense and that someone can help me :)
Note that I am using excel 2010 and need a normal formula as I can not use scripting for this document.
EDIT:
Here is what I have so far, note that the spreadsheet I am using is far more complex than the "simple" example I have in the question...
=IF(ISNUMBER(FIND("RuhrP";F9));LOOKUP(A9;Ruhrpumpen!A$5:A$100;Ruhrpumpen!I$5:I$100);"")
This is showing "RuhrP" in every answer where "RuhrP" is found in F9 and not the answer I want which should be that found in RuhrPumpen!I$5:I$100 where the cell index is the same as that for the A coloum where A9 was found. Again, sorry for the complexity I cant think of any better way to word it.
I note you suggested this formula
=IF(ISNUMBER(FIND("RuhrP";F9));LOOKUP(A9;Ruhrpumpen!A$5:A$100;Ruhrpumpen!I$5:I$100);"")
.....but LOOKUP isn't appropriate here because I assume you want an exact match (LOOKUP won't guarantee that and also data in lookup range has to be sorted), so VLOOKUP or INDEX/MATCH would be better....and you can also use IFERROR to avoid the IF function, i.e
=IFERROR(VLOOKUP(A9;Ruhrpumpen!A$5:Z$100;9;0);"")
Note: VLOOKUP always looks up the lookup value (A9) in the first column of the "table array" and returns a value from the nth column of the "table array" where n is defined by col_index_num, in this case 9
INDEX/MATCH is sometimes more flexible because you can explicitly define the lookup column and the return column (and return column can be to the left of the lookup column which can't be the case in VLOOKUP), so that would look like this:
=IFERROR(INDEX(Ruhrpumpen!I$5:I$100;MATCH(A9;Ruhrpumpen!A$5:A$100;0));"")
INDEX/MATCH also allows you to more easily return multiple values from different columns, e.g. by using $ signs in front of A9 and the lookup range Ruhrpumpen!A$5:A$100, i.e.
=IFERROR(INDEX(Ruhrpumpen!I$5:I$100;MATCH($A9;Ruhrpumpen!$A$5:$A$100;0));"")
this version can be dragged across to get successive values from column I, column J, column K etc.....
Assuming
source data range is A1:B100.
query cell is D1 (here you will input Police or Fire).
result cell is E1
Formula in E1 = VLOOKUP(D1, A1:B100, 2, FALSE)
I figured out such data design:
Main sheet:
Column A: Pump codes (numbers)
Column B: formula showing a corresponding row in sheet 'Ruhrpumpen'
=ROW(Pump_codes)+MATCH(A2;Ruhrpumpen!$I$5:$I$100;0)
Formulae have ";" instead of ",", it should be also German notation. If not, pleace replace.
Column C: formula showing data in 'Ruhrpumpen' column A from a row found by formula in col B
=INDIRECT("Ruhrpumpen!A"&$B2)
Column D: formula showing data in 'Ruhrpumpen' column B from a row found by formula in col B:
=INDIRECT("Ruhrpumpen!B"&$B2)
Sheet 'Ruhrpumpen':
Column A: some data about a certain pump
Column B: some more data
Column I: pump codes. Beginning of the list includes defined name 'Pump_codes' used by the formula in column B of the main sheet.
Spreadsheet example: http://www.bumpclub.ee/~jyri_r/Excel/Data_from_other_sheet_by_code_row.xls
Guys Its very interesting to know that many of us face the problem of replication of lookup value while using the Vlookup/Index with Match or Hlookup.... If we have duplicate value in a cell we all know, Vlookup will pick up against the first item would be matching in loopkup array....So here is solution for you all...
e.g.
in Column A we have field called company....
Column A Column B Column C
Company_Name Value
Monster 25000
Naukri 30000
WNS 80000
American Express 40000
Bank of America 50000
Alcatel Lucent 35000
Google 75000
Microsoft 60000
Monster 35000
Bank of America 15000
Now if you lookup the above dataset, you would see the duplicity is in Company Name at Row No# 10 & 11. So if you put the vlookup, the data will be picking up which comes first..But if you use the below formula, you can make your lookup value Unique and can pick any data easily without having any dispute or facing any problem
Put the formula in C2.........A2&"_"&COUNTIF(A2:$A$2,A2)..........Result will be Monster_1 for first line item and for row no 10 & 11.....Monster_2, Bank of America_2 respectively....Here you go now you have the unique value so now you can pick any data easily now..
Cheers!!!
Anil Dhawan

Resources