How to manually map columns in Excel with different headers - excel

I want to write a function similar to simple Index-Match or Vlookup-Match.
Problem:
The values of the "Kadabra" columns should be shown in the "Jam" column and the "Shadabra" column in the "Jim" column. Given that the Columns will have consistent headers(Jim, Jam, Kadabra, Shadabra) but their positions may change(which means we cannot use column numbers).
"Abra" and "Jimmy" are the index values.
I'm looking for an excel formula solution. If there isn't one then a Visual Basic solution is also welcome.

One way to achieve this would be to use an Index Match Match formula as below, if you were to enter this formula into cell B8:
=INDEX($A$1:$C$4,MATCH(A8,$A$1:$A$4,0),MATCH("Kadabra",$1:$1,0))
And in C8:
=INDEX($A$1:$C$4,MATCH(A8,$A$1:$A$4,0),MATCH("Shadabra",$1:$1,0))
Then you could fill the formula down and it should bring the appropriate values into your Jimmy/Jim/Jam Table.

First please check below screenshot:
I have created a match table at E:F in order to avoid nested IFs for that condition. You may move the match table to another sheet and change your formula accordingly.
Formula for B8 is as below. You may drag-copy it down and right:
=VLOOKUP($A8,$A$2:$C$4,MATCH(VLOOKUP(B$7,$E:$F,2,0),$A$1:$C$1,0),0)

Related

Excel - How to count the number of distinct texts of a specific date inside a table?

I'm trying to count the number of distinct text from a specific date in a data table.
Data Sample with expect result :
I was able to figure out how to count the distinct element from a range I specify, because I can determine the first and last row containing the date.
=SUMPRODUCT(1/COUNTIF(B2:B15,B2:B15))
I have tried to modify my formula so that it determines the cell range by itself but without success.
I searched for an answer, using a combination of CELL and MAXIFS, example below, but Excel does not accept the formula.
=CELL("row",MAXIFS(A2:A15,A2:a15,D2))
I've looked at the INDEX formula, but I can't figure out how to do what I want to do. 😑
Any idea what I'm doing wrong, or what I should be doing instead?
Thanks, I appreciate it!
If you have Office 365 and the new Dynamic Arrays, this sort of formula has become ridiculously easy.
This formula in cell E3:
=COUNTA(UNIQUE(FILTER($B$2:$B$15,$A$2:$A$15=D3)))
Copy down.
You can also generate the unique list of dates with this formula in D3, which spills down automatically and does not need to be copied.
=UNIQUE(A2:A15)
It wasn't easy, but by separating each step of the problem, I was able to solve it.
Note that my solution only works because my dates are sorted.
Here's the final formula in the cell "One formula to rule them all":
=SUMPRODUCT(1/COUNTIF(INDIRECT(CONCATENATE(ADDRESS((MATCH(D3,$A$2:$A$15,0)+1),2),":",ADDRESS(MAX(($A$2:$A$15=D3)*ROW($A$2:$A$15)),2))),INDIRECT(CONCATENATE(ADDRESS((MATCH(D3,$A$2:$A$15,0)+1),2),":",ADDRESS(MAX(($A$2:$A$15=D3)*ROW($A$2:$A$15)),2)))))
Here are my explanations of my process:
Formula if I select the range :
=SUMPRODUCT(1/COUNTIF(B2:B15,B2:B15))
Formula to get the first iteration
=ADDRESS((MATCH(D3,$A$2:$A$15,0)+1),2)
Formula to get the last iteration
{=ADDRESS(MAX(($A$2:$A$15=D3)*ROW($A$2:$A$15)),2)}
Create range from two addresses
=INDIRECT(CONCATENATE(F3,":",G3))
Formula giving me the expect result
=SUMPRODUCT(1/COUNTIF(INDIRECT(CONCATENATE(F3,":",G3)),INDIRECT(CONCATENATE(F3,":",G3))))

EXCEL: How can I check for a keyword in a string, compare it to a range and return the corresponding value in that range?

I need to categorize data: I have a column with the description of the element I'm interested in. I want to check that description for a keyword, then check if that keyword is contained in for example column A of a separate table. If a match is found, I need returned the value in the next column (in this example column B) of the same separate table.
The attached screenshot shows how the data is organized. The column called Column1 is the output I need.
I have actually found a solution, but it involves lots of nesting, I need to force the categories and keywords in the formula and I can't add all the conditions I need; this is the current formula:
=IFERROR(IF(SEARCH("keyword";cellWithDescription);"category";);"OTHER")
And for more categories I repeat the formula instead of "OTHER":
=IFERROR(IF(SEARCH("keyword";cellWithDescription);"category";);IFERROR(IF(SEARCH("keyword2";cellWithDescription2);"category2";);"OTHER"))
which is not ideal, especially with many categories. How can I accomplish the same task with a simpler and more efficient formula, possibly comparing the keyword to values in a table (and not inside the formula itself, as I did now)?
Thanks in advance for your help!
This works for me
=INDEX(category,MATCH(1,--ISNUMBER(SEARCH(keyword,cellWithDescription)),0),1)
enter as array formula, thus ctrl+shift+enter after copying the formula (curly brackets will appear around the formula)

Excel: Find the most common value in array given a certain value (IF, Index, Mode)

I'm trying to find the most common value in a range given a previuous value occurs, so for instance, if Shared mailbox (Col C) is equal to Finance tell me the most common team number (Col B) of the users who access it:
The function I have so far is (obviously ignore the absolute cell references)
=INDEX($B$2:$B$20,MODE(MATCH($C$2:$C$20,$C$2:$C$20,0)))
I could do this with a pivot but I need to insert the value into a cell and vlookup in a pivot wont cut it. Also there are tens of thousands of rows. But essentially the pivot result is what I'm looking to get to, just in a cell via a formula.
Here is an example of the table, a pivot and a peek at the formula and results.
Excel image with pivot
Any and all help is welcome.
Cheers
Matt
You can use an array formulas. Use the mode function over an if
{=MODE(IF($C$3:$C$18=F4,$B$3:$B$18))}
Refer to image for example:
You might be looking for this formula:
=MODE.SNGL(IF(C1:C999="Finance",B1:B999))
CtrlShiftEnter
p.s. you can replace the hard-coded "Finance" with any cell reference.
EDIT
Indeed if there's only one matched row, or two rows with different values, the MODE will fail because there is actually no single mode. You want then to return the "first" match, therefore wrap the formula inside IFERROR with an INDEX/MATCH alternative:
=IFERROR(MODE.SNGL(IF(C1:C999="Finance",B1:B999)),INDEX(B:B,MATCH("Finance",C:C,0)))
CtrlShiftEnter

VLOOKUP alternative using three lookup values

As you know Excel only lets you use one lookup value, but I need to compare three lookup values to find a fourth value.
For example in the screenshot below I want to use the information name, pet and business to find who the teacher is on the second sheet. For the record this is just example data to understand how to perform the task and I need to apply this to over 600 rows!
First sheet:
Here is the first sheet
Second sheet:
Here is my second sheet
Edit: I keep getting an error when I try to enter this formula: =index(Sheet2!A2:G7,MATCH(Sheet1!A5&Sheet!C5&Sheet1!D5,Sheet2!B2:B7&Sheet2!D2:D7&Sheet2!E2:E7,0))
Instead of Vlookup(), you can use Index/Match, which is a nice alternative that lets you do this.
The formula correctly returns "Miss Smith":
Note: This is entered as an array formula with CTRL+SHIFT+ENTER
So, the basic layout of the formula is:
=Index([range to return],match([single look up value],[range where that value would be],0))
You can combine lookup values by concatenating them, as you can see in the screenshot. So, the single lookup values are A2, C2, and D2. And, you'd expect to find "Sarah" in the range G2:G3, "Dog" in H2:H3, etc.
Please let me know if I can clarify anything.
Edit: To help visualize the two sheets thing. I put the table (which you will lookup from) on a sheet called "Data Sheet". The table we need to complete is on "Main WS".
Here's "Main WS":
and the "Data Sheet":
Given the cyclic calulation and disregard for the Worksheet.UsedRange property that the AGGREGATE function exhibits, you will want to cut down the ranges for the lookups to the minimmum required. Pick a column that will typically determine the extent of the lookup range and use that to define the end point of each lookup column.
Sheet2:
        
Sheet1:
        
The formula in Sheet1!E2 is,
        
Fill down as necessary.

Excel, working out with cells

i have some data on excel and i have on column H a list of solutions and on column G a target box that moves from 0 to 100, and i already have a code to generate the solutions in column H , but i want a code to check the target value on column G and checks column H for the nearest solution number and then puts the answer on column I and highlights it.
thank you very much for your time and effort.
You could do without macro, using a service column, say J, and conditional formatting:
on column I place the formula =MAX(J$1:J$100)-J1 and copy/fill till row 100
similarly fill service column J with formula =ABS(G1-H1)
use conditional formatting in column I to highlight where value=0
You probably will need other function names, because spreadsheets use localized interfaces. For instance, for my test I used LibreOffice in Italian...
HTH
I am assuming that the 'solutions' are positive numbers. If these solutions are arranged in ascending order, then you can use the following formula. If not, one solution can be to use a helper column to sort the values in ascending order.
Let your list of solutions in column H be from H1:H100, and your target box is in cell G1.
Then you can copy the following formula to the cell you want.
=IF(MAX(H1:H100)<=G1,MAX(H1:H100),IF(INDEX(H1:H100,1+MATCH(G1,H1:H100))-G1>G1-INDEX(H1:H100,MATCH(G1,H1:H100)),INDEX(H1:H100,MATCH(G1,H1:H100)),INDEX(H1:H100,1+MATCH(G1,H1:H100))))
Replace H1:H100 everywhere in the above formula, with the range in which solutions are present in ascending order. Also, replace G1 everywhere with the address of the cell with the target value.
If solutions are not in an ascending order, then you can use a helper column. You use one extra column for sorting the solutions into an ascending order. If your solutions are present in H1:H10, then in cell I1, you can enter the following formula.
=IF(ISERROR(SMALL($H$1:$H$100,ROW()-ROW($I$1)+1)),"",SMALL($H$1:$H$100,ROW()-ROW($I$1)+1))
Replace $H$1:$H$100 in the formula with the range in which solutions are present. Also, replace $I$1 with the cell address of the same cell where you are copying this formula. Here, since I am copying this formula into I1, I have used $I$1.
Now copy this formula down till where you have the solutions, e.g. for this example, you will copy it down upto I100 since your solutions are from H1:H100.
Now in the previous formula, replace H1:H100 with I1:I100, as this new list is sorted in an ascending order.
If this is not what you are looking for, maybe you could give me some more details, as your question is not very clear. Hope this helps.
P.S. : You can add the highlighting later, if you get the value that you require.

Resources