I have 3 columns,
Afghanistan
Benin
Country
The first 2 columns contains decimal values in them and also some blank spaces in between(represented by '-'). What I want to achieve is that I want to check if Afghanistan column has any value in it, if yes, then the corresponding cell of country column in that row should have Afghanistan in it and if in that same row, Benin column has value, then the Country column should have Benin in it and if both have values in them then Country cell should have Afghanistan, Benin in it. Also, if there is a value already present in the Country column, then it should not be changed. How can it be achieved?
Please help me as I'm a total newbie in excel.
Thanks
Please see this picture
What you might need is the =ISBLANK() worksheet function, which can check if a cell is empty or not. This is to be combined with an =IF() formula:
=IF(ISBLANK(A2);"Value if true";"Value if false")
When you put this, let's say in cell B2, you'll get the expected result.
When you want to check if anything is present inside a column, you might do this:
=LEN(TEXTJOIN("",FALSE,B2:B6))
This concatenates column B (from B2 to B6), using an empty string delimiter, and takes the length of the result. In case there's nothing in that entire column, the length will be zero.
Without VBA, assuming a new Country (I name it Country2) column as a solution is acceptable.
Also assume the the 3 original column is A:C & Country2 column is D. Put this is D2 and drag downwards :
=IF(C2="",IF(AND(B2="-",A2="-"),"",IF(B2="-","Afghanistan",IF(A2="-","Benin","Afghanistan,Benin"))),C2)
Idea : convert all you logic to nested if. The Column D is your desired column.
how it work:
=IF(C2="", ... ,C2) If C2 is not empty, take C2 value. If It is empty, do (...)
IF(AND(B2="-",A2="-"),"", ... ) If both A2 & B2 is empty put a blank : "" , else do (...)
IF(B2="-","Afghanistan", ... ) If only B2 is equal to "-", put "Afghanistan", else do ...
IF(A2="-","Benin","Afghanistan,Benin") If only A2 is equal to "-", put "Benin", else put "Afghanistan,Benin" .
Related
I need to compare the date of a cell against a column that has multiple date and I see which one it matches and get the associated value. Here I put an image to explain myself better:
Column D is where I need to put the formula, which compares the dates in column A on sheet 1 with the dates in column A on sheet 2. If it matches, I need to multiply the values in column C on sheet 1 by the values in column B of sheet 2.
Here another image with an example to be clearer
I have a little idea that would be something like:
= YES (ERROR (MATCH (Sheet1! A4; Sheet2! A2: A32; 0)); Sheet1! C4 * X
In the x it should go B3, but I don't know how to get that cell in the search above.
Try this:
=VLOOKUP(A3,sheet2!A:B,2)*C3
I have recreated your spreadsheets below.
I am trying to search from inside spreadsheet 1 into spreadsheet 2 for 2 things that must be true and if so, pull back another column row.
I want to search column A for the number 12345 and column B for the string "GBP" but I do not know what row 12345 and "GBP" will occur on. If found (there can only ever be 1 result returned so don't worry about multiple results) I need to return the value in column C.
The thing is - I am finding this tricky. Can you help me please?
Create a column C where each cell to the right of data contains the formula
=IF(AND(A2=12345,B2="GBP"),1,0)
When you have copied that formula into each cell down the entire column, search that column for a "1". The "1" is what you are looking for.
As long as there is 1 row matching the criteria, you can use SUMIFS function to get the value from the matching cell:
assuming A2=12345 and B2="GBP" on the current sheet,
sum all values on Sheet 1 column C where both columns A and B match the specified criteria:
=SUMIFS(Sheet1!C:C,
Sheet1!A:A, A2,
Sheet1!B:B, B2)
I am trying to find a value within an array and then return the value in a specific row in the corresponding column.
In the example below, I need to know which bay the Chevrolet is in:
Column A Column C Column D Column E
Chevrolet Bay 1 Bay 2 Bay 3
Toyota Ford Saturn
Honda Chevrolet Jaguar
Ferrari Subaru Lexus
Mitsubishi Hundai BMW
I am looking for Chevrolet in the array C2:E5. Once it determines that the Chevrolet is in Column D, I need for it to return the value in D1. If it was in column E, I need it to return the value in E1.
Any help would be greatly appreciated. Thank you so much in advance.
Try this Array Formula:
=INDEX($C$1:$E$5,1,SMALL(IF(NOT(ISERROR(SEARCH(A1,$C$1:$E$5))),COLUMN($A:$C),99^99),1))
or if you are sure that each column contains exactly what's being searched it can be written like this:
=INDEX($C$1:$E$5,1,SMALL(IF($C$1:$E$5=A1,COLUMN($A:$C),99^99),1))
Enter formula in any cell by pressing Ctrl+Shitf+Enter.
How does it work?
Our ultimate goal is to find the Column that contains the match:
First we did the search for the match using this formula: SEARCH(A1,$C$1:$E$5). It just checks if any of the entries matched A1. Actually, it can be simplified to $C$1:$E$5=A1 but I'm not sure if all entries in each column match exactly what's in A1.
That formula will produce an array of values when entered as array formula. Something like: {SEARCH(A1,C1), SEARCH(A1,D1), SEARCH(A1,E1);... SEARCH(A1,E5)}. The result will be array of number(s) and error (if non was found). But we don't want that, else we will be returning error everytime.
We then use IF(NOT(ISERROR(SEARCH(A1,$C$1:$E$5))),COLUMN($A:$C),99^99). This formula returns the Column Number if there is a match and a relatively huge number 99^99 otherwise. Result would be: {99^99, 99^99, 99^99, 2, ..., 99^99}.
And we are close to what we need since we already have an array of Column and huge number. We just use SMALL to return the smallest number which in my opinion is the lowest Column Number where a match is found. So SMALL(IF(NOT(ISERROR(SEARCH(A1,$C$1:$E$5))),COLUMN($A:$C),99^99),1) would return 2. Which is the column where Chevrolet is referenced at $C$1:$E$1.
Since we already have the column number we simply use INDEX Function which is: INDEX($C$1:$E$5,1,2).
Note: 99^99 can be any relatively large number. Not necessarily 99^99. Actual 16385(max column number in Excel 2007 and up + 1) can be used.
Result:
Another quick and dirty answer is to put a "dummy" row above the entire data set and then determine which placeholder column returned the correct result.
In B1, you can put the equation
=MATCH($A$2,B3:B6,0)
And then in C1, you can put
=MATCH($A$2,C3:C6,0)
And so on until you've covered all the rows and columns. Change the B3:B6 & C3:C6 to reflect the actual rows of data in the given column.
Now, the fun array formula which will actually return the bay. I have this array formula in cell A1 and it is looking from B1:D1, but you can move cell A1 anywhere you want and the B1:D1 range should be all the dummy columns you made above. Also, this is assuming that the bays you want are in row 2 (if they are in a different row, change R2C to R#C where # is the row number). In order to properly enter, enter the formula and then press CTRL+SHIFT+ENTER.
=INDIRECT("R2C"&SUM(IF(ISERROR(B1:D1),FALSE,B1:D1))+1,FALSE)
If the formula is entered properly, it will show curly brackets { } around the equation when you single click on the cell.
This formula will do it, assuming that the lookup value is in A1:
="Bay "&SUMPRODUCT((B2:D5=A1)*(COLUMN(B2:D5)))-1
You could easily adjust it to add more rows and columns.
The formula returns the column number that contains the lookup value and concatenates it with the word Bay to return the exact result you want.
The -1 at the end adjusts for the fact that the Bay 2 column is actually the third column in the worksheet, so you might need to adjust that offset as well.
The SUMPRODUCT function is much undervalued. More on it here:
http://fiveminutelessons.com/learn-microsoft-excel/multiply-two-columns-and-add-results-using-sumproduct
The SUMPRODUCT formula above is perfect for what I want.
E.g. to find the location - COLUMN and ROW - of a given value at A1 in a 2D Range A2:J44
use: =SUMPRODUCT((A2:J44=A!)*(COLUMN(A2:J44))) gives the Absolute* COL#
and : =SUMPRODUCT((A2:J44=A1)*(ROW(A2:J44))) gives the Absolute* ROW#
(not where it is in the range)
These can then be used in e.g. INDEX() or CELL() etc functions.
I have an Excel table with 4 columns and need to find the values that are the same in ALL 4 of the columns and put them aside. Trying to figure out how to accomplish this in Excel.
Example:
Column 1 Column 2 Column 3 Column 4
A1 B1 B1 A1
B1 C2 C1 B1
C2 D3 C2 C2
In this example, both B1 and C2 values comply and must be set aside.
Put this formula in cell D1 and drag and drop it till the end of your values:
=IF(AND(COUNTIF($B$1:$B$3,A1)>0,COUNTIF($C$1:$C$3,A1)>0,COUNTIF($D$1:$D$3,A1)>0),A1,"not found")
For the record, the french version:
=SI(ET(NB.SI($B$1:$B$3;A1)>0;NB.SI($C$1:$C$3;A1)>0;NB.SI($D$1:$D$3;A1)>0);A1;"not found")
To generate a list of values that appear in all four columns, try in cell F2:
=INDEX(A$1:A$3,MATCH(TRUE,COUNTIF(B$1:B$3,A$1:A$3)*COUNTIF(C$1:C$3,A$1:A$3)
*COUNTIF(D$1:D$3,A$1:A$3)*NOT(COUNTIF($F$1:F1,A$1:A$3))>0,0))
confirmed with CTRL+SHIFT+ENTER and fill down as far as needed (this assumes F1 is blank or contains unrelated data)
I couldn't get the above examples to work for myself, so I came up with another solution. Hopefully this will help someone else out there:
=IF(ISNUMBER(MATCH($A2, $B$2:$B$4, 0)), IF(ISNUMBER(MATCH($A2, $C$2:$C$4, 0)), IF(ISNUMBER(MATCH($A2, $D$2:$D$4, 0)), $A2, ""), ""), "")
This checks the value in "Column 1" ("A" column in excel) against the next 3 columns (B,C,D). If the value is present in all three it returns the A column value. If it is not present in all 3, it returns empty. If you would rather return something else, put that something in between the empty quotation marks.
For your data, enter in the lengths of the searched columns, B through D. For example, where it says, "$B$4", put in "$B$99" if the cells go down to 99, but it should work if you put in a generically high number, for example, 99999.
Put this in the row of the first value, so here that would be E2, and then copy it down to every row that has a value in column A.
The function works by just nesting IF statements, and can be expanded or contracted depending on how many columns you want to check against. The function can also be easily modified into a "check if in column B OR column C" function pretty easily.
here is an example for 1 value; I can't generalize since I did not see your data source
Sub test()
If (Range("D6").Value = Range("D6").Offset(0, 1).Value) Then
MsgBox "match"
End If
End Sub
you can also delete duplicates across multiple Columns by using DATA-> Remove Duplicates.
How to solve this case:
Suppose there are two columns having same text assigned with values then i need to subtract those values to get the result in a new cell
For eg: if james in cell a1 has been assigned value as 20 in cell b1 and also james in cell c2 has been assigned value as 40 in cell d2, then i need to get the result as (40-20=20) in a different cell such that while giving the formula the James in cell a1 and c2 has to be same and only there corresponding values get subtracted and not with any other cell.
Please help me on this.
I find it a little strange that you would be starting with C and subtracting A, but okay. If what you are doing is looking for a name in C and taking the number in the right column then subtracting that from the value to the right of the same name in A, then VLookup has you covered:
=VLOOKUP("james",C:D,2)-VLOOKUP("james",A:B,2)
You can also use a formula based on INDEX and MATCH, which doesn't require cells to be sorted (as VLOOKUP does):
=INDEX(B:B; MATCH("James";A:A;0)) - INDEX(D:D; MATCH("James";C:C;0))
If either A:A or C:C doesn't have a "James", then the formula will return #NA. You can avoid this by adding a conditional to check whether the match is valid.
For example, if column C might not contact "James", replace
INDEX(D:D; MATCH("James";C:C;0))
with:
IF(ISNA(MATCH("James";C:C;0)); 0; INDEX(D:D; MATCH("James";C:C;0)))
which will then return 0 if there is no James in column C, otherwise the corresponding value in column D will be returned.