Excel, working out with cells - excel

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.

Related

Excel formula to return an adjacent value when two cells match

Here is what I'm looking for. I need to have Excel return a specific value from an adjacent key when 2 cells match. I attached 2 images here to explain what I'm looking to do. The first image is where I'm currently at and the second image is where I want to get to.
So for example I need Excel to match cell A1 to J1 and drop the value in K1 into cell E1 (red cell). I then of course need to run this down all of column E, asking excel to match the number in column A with a number in column J then dropping the appropriate dollar value into column E.
I've tried the VLOOKUP, INDEX, MATCH formulas and none of them seem to give me the answer.
You're on the right track - this is exactly what VLOOKUP and INDEX/MATCH are for!
Here's the solution in this case:
=INDEX($K$1:$K$10, MATCH($A1, $J$1:$J$10, 0))
I'd generally prefer INDEX/MATCH to VLOOKUP especially if you plan to add columns to your spreadsheet. If you however prefer the VLOOKUP solution, it's as #Warcupine commented:
=VLOOKUP($A1,$J$1:$K$10,2,FALSE)
If you're rocking a newer version of Excel (2019+), XLOOKUP provides the best of both worlds in my opinion (stable and concise):
=XLOOKUP($A1,$J$1:$J$10,$K$1:$K$10)

Get list of rows with a second non-blank value and the column header for the second non-blank occurrence

I have an Excel sheet with data represented as below:
I need to get all the sites with a second non-blank column in the site's row (except Site, of course) and also get the Column Header value.
In the example, sites B, F and G have a second Y. So the result should be:
I am not very well versed with Excel Formulas, but I have experimented a bit with INDEX and I can find the second non-blank value itself. But I can't figure out a way to return the result I require.
Using the below formula I get as far as this, but still nowhere near my expected result.
{=INDEX(B2:I2,SMALL(IF(B2:I2<>"",COLUMN(B2:I2)-COLUMN(B2)+1),2))}
Edit:
With #Harun24HR 's answer I get this new result.
Try below formula.
=INDEX($B$1:$I$1,,SMALL(IF(($B$2:$I$11="Y")*($A$2:$A$11=C14)>0,COLUMN($B$2:$I$11),""),2)-1)
May need array entry with CTRL+SHIFT+ENTER.
Edit#: As per my below screenshot I have used below formulas.
For result column in J2 cell put
=IF(COUNTIF(B2:I2,"<>")>1,ROW(),"")
In C14 put
=IFERROR(INDEX($A$1:$A$11,SMALL($J$1:$J$11,ROW(1:1))),"")
And in D14 cell put below formula.
=INDEX($A$1:$I$1,MAX(($B$2:$I$11<>"")*($A$2:$A$11=C14)*(COLUMN($B$2:$I$11))))
Please note. You no need to array entry for these formulas.
Finally I ended up solving this using a combination of the accepted answer (by #Harun24HR) and How To Extract A Dynamic List From A Data Range Based On A Criteria Without Filters In Excel
In J2 through J11, I added the formula:
{=IFERROR(INDEX($B$1:$I$1,,SMALL(IF(($B$2:$I$11<>"")*($A$2:$A$11=A2)>0,COLUMN($B$2:$I$11),""),2)-1), "")}
In A15 to A24 (same number of rows as the original range), I added the formula:
{=IFERROR(INDEX($A$2:$A$11,SMALL(IF($J$2:$J$11<>"",ROW($A$2:$A$11)),ROW(1:1))-1,1),"")}
In B15 to B24, it's a simple VLOOKUP:
=IFERROR(VLOOKUP(A15,$A$2:$J$11,10,0),"")
This way, the result table is dynamic.

Count occurrences of values in a specific range (Excel) (no VBA)

I need to count all of the occurrences of a given value from a specific range of cells (containing strings or numbers), depending on a parameter stored in another cell.
I prepared a simple Excel table as an example (see attached image): let's say I want to count all of the occurrences of the VALUE "4" for the BASE "100". The result should be: 2 (C4 + C5).
Attached image
I tried to use COUNTIFS and FIND functions but with no results. The former only considers exact values (so the 4 in cell C5 will be ignored) while I seem to be unable to add another condition - the BASE column - to the latter.
Fact is I need to solve this with formulas only, no programming.
Thanks in advance for your help!
Use the SUMPRODUCT:
=SUMPRODUCT(($B$2:$B$10=100)*(ISNUMBER(SEARCH(4,$C$2:$C$10))))
There's a couple of other approaches, the simpler one is just to add another column which identifies matches for you, then have your count just sum the results of that column.
Solution image
So we put the values we want to find in some reference cells, the BASE match goes in G2, and the VALUE we're looking for goes in G3.
In column D we put a formula in D2:
"=IF(B2=$G$2,IF(ISERR(SEARCH($G$3,C2)),0,1),0)"
Returns 0 if the BASE matches and we can find at least one occurent of VALUE
B2=$G$2 - Does the BASE column match the BASE we're looking for
ISERR(SEARCH($G$3,C2)) - Does searching for the VALUE return an error (if it does, we know that VALUE isn't there)
Copy this formula to all the cells in column D, and then you can just use a simple SUM(D:D) to count the occurences where your conditions are met.
The neater but slightly more complex alternative is to use an array formula to do the match finding and counting all in one formula. This would look like this:
"{=SUM(IF(B:B=$G$2,IF(ISERR(SEARCH($G$3,C:C)),0,1)))}"
Pretty much the same as the formulas in column D, but now we use B:B and C:C in place of B2 / C2 etc. and stick the SUM around the whole thing. If you finish editing with Ctrl+Shift+Enter instead of just Enter, that'll make it an array formula.
Microsoft Array Formula Guidelines
NB: this WILL NOT count multiple occurences of 4 in a single VALUE cell.
p.s. Assuming you would want it to actually return 3 in this case (you missed the 4 in C7)

Excel: How to sum values associated with certain strings in different columns

Excel Example Image
Hi there! My problem is a little hard to describe so I hope the title isn't misleading.
As you can see in the image, there is a column of different 2-letter-strings with associated values in another column next to them. On the right there is another table with all the strings and a column next to it where I want Excel to sum all the values that are associated with that particular string.
So Excel has to basically scan trough the string column on the very left and check for "GE" for example. If it is successful in finding it, it has to refer to the cell in the same row that references the value and then add this value into the cell where it sums all the "GE" values.
I tried some different things already but I wasn't able to find a solution. I hope you can help me! :)
You'll have to use the SUMIF function. Enter it in every cell of column G where you want to see the result. As an example, G3 cell should be:=SUMIF(B3:B12,"GE", D3:D12)EDIT: You could also pick the value from F column to avoid typos in the function, so you can also do it like:=SUMIF(B3:B12,F3, D3:D12)

search multiple columns for a value and concatenate the address of the cells

I have been breaking my head over this formula for sometime now. I have found a solution which is too big and not so convenient to use every time. So can any Excel Expert give me a solution/suggestion?
Column A contains 150 values. Column D to R contains a table in which I need to look up the values in A one by one. I want to return address of all the cells that contains the value.
For example, Value in A2 is present in cells D5, E15, H10, R3 then my result should be D5,E15,H10,R13.
Please Note that some columns may not contain the value of A2, I do not want them displayed.
Here is the formula I have written:
=CONCATENATE(
IF(A2=IF(COUNTIF(D:D,A2),VLOOKUP(A2,D:D,1,FALSE),""),ADDRESS(MATCH(A2,D:D,0),4,4),0),",",
IF(A2=IF(COUNTIF(E:E,A2),VLOOKUP(A2,E:E,1,FALSE),""),ADDRESS(MATCH(A2,E:E,0),5,4),0),",",
IF(A2=IF(COUNTIF(F:F,A2),VLOOKUP(A2,F:F,1,FALSE),""),ADDRESS(MATCH(A2,F:F,0),6,4),0),",",
IF(A2=IF(COUNTIF(G:G,A2),VLOOKUP(A2,G:G,1,FALSE),""),ADDRESS(MATCH(A2,G:G,0),7,4),0),",",
IF(A2=IF(COUNTIF(H:H,A2),VLOOKUP(A2,H:H,1,FALSE),""),ADDRESS(MATCH(A2,H:H,0),8,4),0),",",
IF(A2=IF(COUNTIF(I:I,A2),VLOOKUP(A2,I:I,1,FALSE),""),ADDRESS(MATCH(A2,I:I,0),9,4),0),",",
IF(A2=IF(COUNTIF(J:J,A2),VLOOKUP(A2,J:J,1,FALSE),""),ADDRESS(MATCH(A2,J:J,0),10,4),0),",",
IF(A2=IF(COUNTIF(K:K,A2),VLOOKUP(A2,K:K,1,FALSE),""),ADDRESS(MATCH(A2,K:K,0),11,4),0),",",
IF(A2=IF(COUNTIF(L:L,A2),VLOOKUP(A2,L:L,1,FALSE),""),ADDRESS(MATCH(A2,L:L,0),12,4),0),",",
IF(A2=IF(COUNTIF(M:M,A2),VLOOKUP(A2,M:M,1,FALSE),""),ADDRESS(MATCH(A2,M:M,0),13,4),0),",",
IF(A2=IF(COUNTIF(N:N,A2),VLOOKUP(A2,N:N,1,FALSE),""),ADDRESS(MATCH(A2,N:N,0),14,4),0),",",
IF(A2=IF(COUNTIF(O:O,A2),VLOOKUP(A2,O:O,1,FALSE),""),ADDRESS(MATCH(A2,O:O,0),15,4),0),",",
IF(A2=IF(COUNTIF(P:P,A2),VLOOKUP(A2,P:P,1,FALSE),""),ADDRESS(MATCH(A2,P:P,0),16,4),0),",",
IF(A2=IF(COUNTIF(Q:Q,A2),VLOOKUP(A2,Q:Q,1,FALSE),""),ADDRESS(MATCH(A2,Q:Q,0),17,4),0),",",
IF(A2=IF(COUNTIF(R:R,A2),VLOOKUP(A2,R:R,1,FALSE),""),ADDRESS(MATCH(A2,R:R,0),18,4),0))
As I said, this works but I am looking for a simpler and smaller formula.
Hint: Maybe using array can help?
Thanks in advance :)
What you are trying to accomplish is not a great fit for Excel formulas, but it can be done with a smaller, simpler formula dragged across 15 columns instead of 1 giant complicated formula that tries to do everything at once.
Assuming column A has 150 values (from A1 to A150), and there is a table going from D1 to R50...
Enter =S1&IFERROR(","&ADDRESS(MATCH($A1,D$1:D$50,0),COLUMN(D1)),"") into T1.
Drag the formula across to AH1.
Enter =RIGHT(AH1,LEN(AH1)-1) into AI1.
Select T1 to AI150 and press Ctrl-D.
Column AI1 will contain the results you are looking for.
How does this work?
The formula in T1 begins by taking the result of one cell to the left (which is blank). Then it concatenates this with the address of the first match in column D (prefixed by a comma). If there is no match, it just concatenates blank (""). As you drag this formula to the right, it keeps concatenating addresses as matches come up (or blank if there are none). When you get to the end, you will have looked for matches in all 15 column of your table.
The formula in AI1 just strips off the initial comma if there is one.

Resources