I have an Excel sheet with two columns. The first column holds names. I also have a list of names as text file, now added as second sheet.
For each row, I want to set the second cell to a fixed value if the value of the first cell is present in the list. Other rows should remain unchanged.
I was told to consider VLOOKUP but could not make up a formula.
I'm using Excel for Microsoft 365
first sheet:
column M is the one to be changed
second sheet:
The expected output would simple have entries in column M to be IN instead of OUT.
Try COUNTIF:
=IF(COUNTIF(List!A:A,A1),"IN","OUT")
You can do it with MATCH if the Second Sheet is in the same workbook. If it is in a separate workbook, it will still work, but only of the other workbook is open.
=IF( ISNUMBER( MATCH( A2,Sheet2!$A$2:$A$7, 0 ) ), "IN", "OUT" )
Alternatively, if you don't want to do VBA, you can pull the text file into a table in your workbook that is hidden into the data model and then reference it, but that is a long trip and can only be done on an installation that supports Power Query.
Formula would be somethin like
=VLOOKUP(K3,Table1,2)
Where Table1 is your look up, K3 is the value to look up (index) and 2 is the second column you want to return
[
Related
A problem that I am trying to do is extract rows out of a spreadsheet. The spreadsheet has over 1200 entries. I have split them up into relevant worksheets so the information can be used. Each of the individual codes will be a worksheet
A sample of the data looks like
The formula that I have found is and trying to run from a separate work sheet is
INDEX(Master!$A$2:$D$13, SMALL(IF((INDEX(Master!$A$2:$D$13,,4,1)="wap"),
MATCH(ROW(Master!$A$2:$D$13),ROW(Master!$A$2:$D$13)), “”), ROWS(A2:$A$2)), ,1)
It fails on
MATCH(ROW(Master!$A$2:$D$13),ROW(Master!$A$2:$D$13))
Getting the dreaded #N/A
I need some help in solving the problem and a brief explanation of the solution would be helpful.
Unfortunately, it has to be done by formula, as I don't have access rights for a VBA query.
Here you go:
=IFERROR(
INDEX(Master!$A$2:$D$13,
SMALL(
IF(
INDEX(Master!$A$2:$D$13,,4)="wap",
INDEX(Master!$A$2:$D$13,,1),
COUNTA(Master!$A$2:$A$13)+1
),
ROWS(A2:$A$2)
),
COLUMN()
)
,"")
This must be entered as an array function. Instead of clicking out of the cell or pressing enter to exit the formula, press Ctrl+Shift+Enter.
The IF function iterates through every cell in column 4 of the Master array. If the Code is a match, the ID is passed. Otherwise, the number of master rows plus one is passed. This is important because it will produce an error in the final INDEX function, which will be escaped to "" (a blank string).
The SMALL function outputs the current row, or key in the generated array. The final INDEX function gets the intersect of the current column and the chosen row. Just copy this across however many columns you have on each sheet and down the number of rows that should be returned. Any additional rows (or columns) will pass the blank string. To be safe, I'd copy down the 1200 rows, but this could slow your processing (if it does, just set the calc mode to manual).
I have an excel document with two sheets, data and edu-plan. The sheet data has the following information:
The sheet edu-plan looks like this:
My question is: how do i create an excel formula that checks if the target group on the specific row in edu-plan! has the course name in question on the same row as the target group in sheet data!, i.e. if Sales and Sales course is on the same row in the sheet data!?
In reality, the data sheet as a couple of hundred rows and will change over time, so i am trying to develop a formula that i can apply easily on all rows/columns in edu-plan!.
The desired result in edu-plan would look like this:
A pivot table might be a good way to go.
If you would like to do it by formula, then you can just use a COUNTIFS
=IF(COUNTIFS(data!$A$2:$A$10,$A2,data!$B$2:$B$10,B$1),"X","")
A possible way to solve your issue with an array formula:
Write in B2 of sheet edu-plan
{=IFERROR(IF(MATCH('edu-plan'!$A2&'edu-plan'!B$1,data!$A$2:$A$6&data!$B$2:$B$6,0)>0,"x",""),"")}
Since it is an array formula, you need to hit shift + ctr + enter.
Here is the formula broken down:
MATCH('edu-plan'!$A2&'edu-plan'!B$1,data!$A$2:$A$6&data!$B$2:$B$6,0)
checks whether the combination of row header and column header is in the data table. MATCH returns the index of the found combination. Since we are not interested in the location, we only ask IF(MATCH > 0, "x", "") to write an "x" if a match was found. If MATCH finds nothing, it returns an error, which is why we add an IFERROR(VALUE, "") around the construct.
We have organized data outputs from SPSS in the following format. It has ID (based on concatenate) , Country, Species, Product and then the predictors followed by the respective coefficients.
In another worksheet I have the same format but the variables are now columns, so I want to bring the coefficients under each column from the previous table.
Thank you for the help
I tried using sumifs to match the IDs and then another criteria to match the column / variables but its definitely wrong. If I used vlookup, I'll need to create new columns for each Predictor?
A simple INDEX/MATCH/MATCH will do it:
In K2:
=IFERROR(INDEX(Sheet2!$A:$O,MATCH($A2,Sheet2!$A:$A,0),MATCH(F2,Sheet2!$1:$1,0)),"")
Where Sheet2 is the sheet on which the values are located.
OFFSET and INDIRECT are volatile functions. INDEX/MATCH is not.
If you need smaller solution, check this one pleas:
=IFERROR(INDIRECT("Sheet1!"&ADDRESS(ROW(),MATCH(F$1,Sheet1!$F2:$J2,0)+10)),"")
copy this formula in Destination Sheet F2, and Paste it on whole destination table as you know.
Suppose that your source data is in Sheet1 (if not, change "Sheet1!" to your source sheet name)
And the numbers are base on your image, for first 5 constants then 5 coefficients, and at last 5 value.
Enter into F2 of second worksheet (if your table starts on A1):
=IFERROR(OFFSET(Sheet1!$K2,,MATCH(Sheet2!F$1,OFFSET(Sheet1!$F2,,,,COUNTA(Sheet1!$F2:$J2)),0)-1),"")
Sheet1!$K2 = field under Coefficient 1 in first worksheet (=10)
Sheet2!F$1 = field above formula in second worksheet (=GDP)
Sheet1!$F2 = field under Predictor 1 in first worksheet (=GDP)
Sheet1!$F2:$J2 = all entries under the Predictors in first worksheet
Now drag it down and then over to the right.
A second approach based on Scott Craners suggestion (I cannot comment yet, but I understand your question slightly different then he does - credits go to him though):
Enter in Sheet2!F2:
=IFERROR(INDEX(Sheet1!$K$2:$O$7,MATCH(Sheet2!$A2,Sheet1!$A:$A,0),MATCH(Sheet2!F$1,Sheet1!$F2:$J2,0)),"")
I have an issue with a vlookup/index-match formula in excel 2010.
I have a table that contains duplicate values in the name column.
I have a table in another sheet that reference the name & amount from the first sheet.
in case a duplicate name exist in the original table, it should sum the amount.
For example, look at the pic below.
ABC is a duplicate name, and it's amount should be zero.
How can I use Vlookup/index-match formulas in order to display "0" in the result when I lookup the name ABC?
In the destination sheet, the name only appears once, hence I don't want to add another ABC to the dest table.
Thanks !
Roni.
VLOOKUP and or INDEX/MATCH will only return you one entry (the first match) - so you cannot use it for summing (unless in an array formula).
However, using SUMIFS (or in Excel 2003 and earlier SUMIF) will be just what you need: So In F2, you could write:
=SUMIFS($C$2:$C$6,$B$2:$B$6,E2)
I know how to make a named range in Excel.
I have a spreadsheet, with various columns going across as parameters, and then finally a formula in the last cell. This is repeated many times in each row, with each row having a different set of data, and the formula updated to reference the correct row index.
However, the formula looks like (three rows worth):
=G2*(10*D2 + 20*E2 + 5*F2)
=G3*(10*D3 + 20*E3 + 5*F3)
=G4*(10*D4 + 20*E4 + 5*F4)
I would like to use named ranges, but I can't find a way to do something like
=Count * (10*var1 + 20*var2 + 5*var3)
where count, var1, var2, and var3 automatically update to be the particular column of the current row. I can create a named range for every cell, but that isn't helpful. I can name range the column, but then I can't find a way to put an offset into the formula.
Also the whole point of this is readability, so if it ends up being some nasty complex formula function call, that probably doesn't help too much.
Simple, at least when using Excel 2010:
name your column: select full column, enter name
use column name in formula; Excel will combine the referenced column with the current row to access a single cell.
Using the example from Alex P:
select column D by clicking the column header containing the "D", enter name "input1" into name field, and press Enter.
repeat for columns E to F, using "input2" and "input3", respectively.
Do not define additional names defining names "input1" [...] as in example above!
use the formula as given in the example above
Attention:
Using named columns this way, you cannot access any other row as the one your formula is in!
At least I'm not aware of the possibility to express something like <ColName>(row+1)...
I would suggest creating a Table. Select your range A1:H4, then go to the Tables widget > New > Insert Table with Headers (on Mac). This will mark A2:H4 as body of the table, and A1:H4 as header.
From that, you get:
Whatever you put into the header column will define the name for this column automatically, e.g. Count, Radius, Density, Height
You can then write your formula using =[#Count]*(10*[#Radius] + 20*[#Density] + 5*[#Height])
When you change the formula in cell H2, Excel will automatically "copy down" this formula to all cells in column H. So no more accidental inconsistencies in the formulas.
When you need to add another row, simply click the last cell (in our example H4) and hit Tab. Excel adds another row, and also makes sure to "copy down" your formula into the new row.
If you need a total row, add it with the Total Row checkbox in the Tables widget. Excel adds a total row automatically. If you click any cell in the total row, you can change the "total formula" with the "▼▲" button, for example to calculate the Average instead of the Sum of the column.
If you have a long table and scroll down so that the header is not visible anymore, Excel automatically displays the column header instead of the column names (Count instead of G for example).
I can really recommend the video You Suck at Excel with Joel Spolsky which explains all of that.
Suppose I have the following numbers set up in columns D to F in rows 2 to 4:
D E F G
2 10 15 20
3 1 2 3
4 20 30 40
Now suppose I want the value in column D to be known as input1, column E to be input2, and column F to input3:
In Insert > Name > Define...
input1 RefersTo =OFFSET(Sheet1!$D$2,0,0,COUNT(Sheet1!$D:$D),1)
input2 RefersTo =OFFSET(Sheet1!$E$2,0,0,COUNT(Sheet1!$E:$E),1)
input3 RefersTo =OFFSET(Sheet1!$F$2,0,0,COUNT(Sheet1!$F:$F),1)
Now if I write my formula in column G as follows I should get correct answers:
G2 =(10*input1+20*input2+30*input3) // 1000
G3 =(10*input1+20*input2+30*input3) // 140
G5 =(10*input1+20*input2+30*input3) // 2000
I haven't fully reviewed the previous answers, but I think this is closer to what #Jason Coyne the OP was looking for. So, I hope I get a lot of up votes. ;-)
Excel allows your formula to refer to tables and columns by name if you "Format as Table". Here is an article titled Using structured references with Excel tables that goes into detail.
FWIW, it looks like this feature has been available since Excel 2007.
Here is a screenshot of an example:
You should be able to see the formula in E2 is =[#Count] * (10*[#Var1] + 20*[#Var2] + 5*[#Var3]) which is pretty close to what #jason-coyne wanted to type.
I don't like that you are forced to pick a style (or define a new one if you don't see a style you like). The good news is you can reformat the cells all you wish without undoing the "tableness".
It insists on turning on auto-filter. But, auto filter is easy to turn off (see the Filter Button checkbox under the Table Tools Design menu).
It also insists on having non-empty, unique values in the header row (Which kinda makes sense). If you delete a header cell, or insert a column, Excel will invent a new, unique name and stuff it in for you. D'oh!
If you want a column to not have a header, you can enter an apostrophe (') followed by one or more blanks. Remember header values need to be unique, so keep adding blanks if you want more than one column without a header.
If you would like to download the sample workbook in the screenshot, here is a link: https://filebin.ca/3vfaSDn4NLEA/SampleWorkbook.xlsx
Adding to Alex P's answer:
Instead of using =OFFSET(Sheet1!$D$2,0,0,COUNT(Sheet1!$D:$D),1) as the formula for input1, I recommend to use =Sheet1!$D$2:INDEX(Sheet1!$D:$D,COUNT(Sheet1"$D:$D))
It produces the same result, but it is non-volatile, i.e., only recalculate when a predecessor cell changes. This is much better in a larger model!
If you're using VBA, then you can select the whole column and name it, say MyCol, in the name box (upper left input box). The in your code you can refer to a cell in the column MyCol (line 12) using the following code:
Cells(12, Range("MyCol").Column)
You might be able to use the row() function. This returns the current row that you are in. So depending on the layout of the spreadsheet you can use it like this:
=offset(NamedColumn1, row()-1)
The -1 is because you are saying how many rows to move down from row 1 which if you are in row 1 you want to be 0.
Use the Excel feature called named references.
To name a cell or range of cells
select that cell or range of cells
Enter its name in the Name Box ( its left of the formula widget and has the cell name )
You can't use names that conflict with cell names, like k0.
The named cells can be used if formulas. E.g.,
=pi*radius*radius
I'd like to propose a slight variation of the cell reference made by Dror. This will work as well:
Range("MyCol").Rows(12)