EXCEL: Find cells via last number - excel

So I need a way to mark the cells where the sequence ends in 4, 5, or 6.
Data
35632
35215
35115
etc.
I don't have an idea of where to start so any help is much appreciated. I know that I can't use the text filters on numbers even if the cell is formatted as text.

You could use one of the following Excel formulas
=OR(MOD(A1,10)=4,MOD(A1,10)=5,MOD(A1,10)=6)
or
=OR(RIGHT(A1)="4",RIGHT(A1)="5",RIGHT(A1)="6")
or (thanks to Scott Craner)
=ISNUMBER(MATCH(--RIGHT(A1),{4,5,6},0))
or
=ISNUMBER(MATCH(MOD(A1,10),{4,5,6},0))
or
=ISNUMBER(FIND(MOD(A1,10),"456"))
or
=ISNUMBER(FIND(RIGHT(A1),"456"))
or
=SUM(IF(MOD(A1,10)={4,5,6},1)) (returns 1 if true, or 0 if false)
OR
=OR(MOD(A1,10)={4,5,6})
Or
=MOD(MOD(A1,10),7)>3
Or
=ABS(RIGHT(A1)-5)<2

Related

Excel - multiple value search across multiple columns or one column with multiple values

I have 7 criteria = TMO-1 through to TMO-7
I have two scenarios to search from.
i have either got a single excel with TMO-6, TMO-201, TMO-67,... etc (some have a lot of values)
or i have split the cell up so the values are all in individual cells such that [TMO-6][TMO-201][TMO-67] etc
I have tried two equations from each. for the first one (the preferred solution) i have tried:
=IF(IFERROR(SEARCH("TMO-1",AB8),0) > 0, "TMO-1",IF(IFERROR(SEARCH("TMO-2",AB8),0) > 0, "TMO-2", "false"))
the problem with that is it finds anything that starts with TMO-1, so will show true if TMO-12 is in the cell.
For option 2 i tried:
=IF(AB9:AR9=TMO-1, TMO-1, IF(AB9:AR9=TMO-2, TMO-2, IF(AB9:AR9=TMO-3, TMO-3,IF(AB9:AR9=TMO-4, TMO-4, IF(AB9:AR9=TMO-5, TMO-5, IF(AB9:AR9=TMO-6, TMO-6, IF(AB9:AR9=TMO-7, TMO-7, "N/A")))))))
and i get the error #spill
any ideas ?
Assuming:
ms365 (Hence the #SPILL error);
The option between concatenated values or seperated (hence AB8 against AB9:AR9);
All numbers are prepended with TMO-;
You are looking for the 1st match in sequence (1-7);
If no match is found, you want to return "Not Found".
First thing that came to mind is to just keep the comma-seperated data in AB8 and use a simple trick to concatenate the delimiters with the sequence:
=ISNUMBER(FIND("-"&SEQUENCE(7)&",",A1&","))
To put that in practice, try:
Formula in B1:
=IFERROR(MATCH("X",IF(ISNUMBER(FIND("-"&SEQUENCE(7)&",",A1&",")),"X"),0),"Not Found")
Other options:
=#IFERROR(SORT(FILTERXML("<t><s>"&SUBSTITUTE(A1,", ","</s><s>")&"</s></t>","//s[substring(.,5)<8]")),"Not Found")
Or, using the insider BETA-functions:
=LET(X,MIN(--DROP(TEXTSPLIT(A1,"-",", "),,1)),IF(X<8,"TMO-"&X,"Not Found"))

Summarize more than one column in Excel COM object

I'm using SubTotal in a Openedge generated Excel book for my first time.
The example of the KB (https://knowledgebase.progress.com/articles/Article/Sample-Code-to-do-Excel-Grouping) is:
chWorksheet:Range("A1"):CurrentRegion:Subtotal(1, -4112, 2, True, False, False).
The parameters for SubTotal are:
GroupBy , Function:, TotalList, Replace:, PageBreaks:, SummaryBelowData:
In "TotalList" the example is 2, which means column 2 is totalized.
In VBA, TotalList can be an array. For example, Array(14, 15) indicates totaling columns 14 and 15.
But I can't make ABL to accept that. It only receives an integer, for one column. Which is sad.
Does anybody if it's possible to totalize more than one column?
Thank you
Instead of an integer, I sent an integer EXTENT variable with the column numbers and it worked perfectly.
Thanks to Tom and Jensd for the help and ideas.

Having trouble in nested IFs in excel with true or false values in each IF statement

=IF(AND(A2<=20151231),(B2=0) 0, 15, IF(AND(A2>=20190101,B2>=2),15, 7.5))
This is what I entered in the function.
if A2 is less than 20151231 and B2 is equal to 0 the value will be 0.
if A2 is greater than 20190101 and B2 is equal to or greater than 2 the value will be 15.
the problem is that excel says that I entered too many arguments and when I try to derive it it says that there is something wrong with the function I entered.
Try this:
=IF(AND(A2<=20151231,B2=0),"0",IF(AND(A2>=20191010,B2>=2),15,""))
it seems your formula has too much close and open parenthesis. When using "and()" enclose all logic in one set of parenthesis.
Hope this helps. Thanks
Reymond's answer is correct, assuming that you want the result to be:
0 - if A2<=20151231 AND B2=0
15 - if A2>=20190101 AND B2>=2
7.5 - if neither of these cases are true.
If you are struggling to see what parameters you are passing to which function, I would suggest that you format your formulas so that they are easier to read:
=IF(
AND(A2<=20151231, B2=0),
0,
IF(
AND(A2>=20190101,B2>=2),
15,
7.5
)
)
This makes it much easier to see what is going on and it can even be done in the excel formula bar if you wish (by using Alt+Enter):

Trouble of finding matching values from a different workbook excel

I have this excel files, this is what my data looks like in the first workbook, which could have 2000 + entries and in a general format.
A
1 5001987
2 1458285
3 2506588
4 4745089
5 2540486
.
.
My other excel file looks like this, but also in a general, but the data within it is generated by something else which results of its output like this.
A
1 ['2506588']
2 ['2540181']
3 ['2553486']
4 ['2540181']
5 ['2540389']
6 ['2553384']
On a specific column somewhere, i have written this function:
=IF(VLOOKUP([outputbarcode.xlsx]Sheet1!$B$4,B2:B1992,2,TRUE),"Y","N")
I simply want it to look if excefile 2 cell A1 value exist in excelfile 1, print Y, if not, N.
Running the function above returns #N/A
Is there something wrong with my function?
On excel file 2, try:
=IFERROR(IF(INDEX(MATCH(VALUE(MID(A1,3,7)), Sheet1!A:A, 0),)>0, "Y"), "N")
Sheet1 is excel file 1 here. I prefer index & match to vlookup. You can search why.
I suggest that you do an edit/replace and remove those odd characters permanently. Then you won't need the mid() function but the rest of #Sangbok lee answer will be fine and that may help with future operations.

How do I sum data based on a PART of the headers name?

Say I have columns
/670 - White | /650 - black | /680 - Red | /800 - Whitest
These have data in their rows. Basically, I want to SUM their values together if their headers contain my desired string.
For modularity's sake, I wanted to merely specify to sum /670, /650, and /680 without having to mention the rest of the header text.
So, something like =SUMIF(a1:c1; "/NUM & /NUM & /NUM"; a2:c2)
That doesn't work, and honestly I don't know what i should be looking for.
Additional stuff:
I'm trying to think of the answer myself, is it possible to mention the header text as condition for ifs? Like: if A2="/650 - Black" then proceed to sum the next header. Is this possible?
Possibility it would not involve VBA, a draggable formula would be preferable!
At this point, I may as well request a version which handles the complete header name rather than just a part of it as I believe it to be difficult for formula code alone.
Thanks for having a look!
Let me know if I need to elaborate.
EDIT: In regards to data samples, any positive number will do actually, damn shame stack overflow doesn't support table markdown. Anyway, for example then..:
+-------------+-------------+-------------+-------------+-------------+
| A | B | C | D | E |
+---+-------------+-------------+-------------+-------------+-------------+
| 1 |/650 - Black |/670 - White |/800 - White |/680 - Red |/650 - Black |
+---+-------------+-------------+-------------+-------------+-------------+
| 2 | 250 | 400 | 100 | 300 | 125 |
+---+-------------+-------------+-------------+-------------+-------------+
I should have clarified:
The number range for these headers would go from /100 - /9999 and no more than that.
EDIT:
Progress so far:
https://docs.google.com/spreadsheets/d/1GiJKFcPWzG5bDsNt93eG7WS_M5uuVk9cvkt2VGSbpxY/edit?usp=sharing
Formula:
=SUMPRODUCT((A2:D2*
(MID($A$1:$D$1,2,4)=IF(LEN($H$1)=4,$H$1&"",$H$1&" ")))+(A2:D2*
(MID($A$1:$D$1,2,4)=IF(LEN($I$1)=4,$I$1&"",$I$1&" ")))+(A2:D2*
(MID($A$1:$D$1,2,4)=IF(LEN($J$1)=4,$J$1&"",$J$1&" "))))
Apparently, each MID function is returning false with each F9 calculation.
EDIT EDIT:
Okay! I found my issue, it's the /being read when you ALSO mentioned that it wasn't required. Man, I should stop skimming!
Final Edit:
=SUMPRODUCT((RETURNSUM*
(MID(HEADER,2,4)=IF(LEN(Match5)=4,Match5&"",Match5&" ")))+(RETURNSUM*
(MID(HEADER,2,4)=IF(LEN(Match6)=4,Match6&"",Match6&" ")))+(RETURNSUM*
(MID(HEADER,2,4)=IF(LEN(Match7)=4,Match7&"",Match7&" ")))
The idea is that Header and RETURNSUM will become match criteria like the matches written above, that way it would be easier to punch new criterion into the search table. As of the moment, it doesn't support multiple rows/dragging.
I have knocked up a couple of formulas that will achieve what you are looking for. For ease I have made the search input require the number only as pressing / does not automatically type into the formula bar. I apologise for the length of the answer, I got a little carried away with the explanation.
I have set this up for 3 criteria located in J1, K1 and L1.
Here is the output I achieved:
Formula 1 - SUMPRODUCT():
=SUMPRODUCT((A4:G4*(MID($A$1:$G$1,2,4)=IF(LEN($J$1)=4,$J$1&"",$J$1&" ")))+(A4:G4*(MID($A$1:$G$1,2,4)=IF(LEN($K$1)=4,$K$1&"",$K$1&" ")))+(A4:G4*(MID($A$1:$G$1,2,4)=IF(LEN($L$1)=4,$L$1&"",$L$1&" "))))
Sumproduct(array1,[array2]) behaves as an array formula without needed to be entered as one. Array formulas break down ranges and calculate them cell by cell (in this example we are using single rows so the formula will assess columns seperately).
(A4:G4*(MID($A$1:$G$1,2,4)=IF(LEN($J$1)=4,$J$1&"",$J$1&" ")))
Essentially I have broken the Sumproduct() formula into 3 identical parts - 1 for each search condition. (A4:G4*: Now, as the formula behaves like an array, we will multiply each individual cell by either 1 or 0 and add the results together.
1 is produced when the next part of the formula is true and 0 for when it is false (default numeric values for TRUE/FALSE).
(MID($A$1:$G$1,2,4)=IF(LEN($J$1)=4,$J$1&"",$J$1&" "))
MID(text,start_num,num_chars) is being used here to assess the 4 digits after the "/" and see whether they match with the number in the 3 cells that we are searching from (in this case the first one: J1). Again, as SUMPRODUCT() works very much like an array formula, each cell in the range will be assessed individually.
I have then used the IF(logical_test,[value_if_true],[value_if_false]) to check the length of the number that I am searching. As we are searching for a 4 digit text string, if the number is 4 digits then add nothing ("") to force it to a text string and if it is not (as it will have to be 3 digits) add 1 space to the end (" ") again forcing it to become a text string.
The formula will then perform the calculation like so:
The MID() formula produces the array: {"650 ","670 ","800 ","680 ","977 ","9999","143 "}. This combined with the first search produces {TRUE,FALSE,FALSE,FALSE,FALSE,FALSE,FALSE} which when multiplied by A4:G4
(remember 0 for false and 1 for true) produces this array: {250,0,0,0,0,0,0} essentially pulling the desired result ready to be summed together.
Formula 2: =SUM(IF(Array)): [This formula does not work for 3 digit numbers as they will exist within the 4 digit numbers! I have included it for educational purposes only]
=SUM(IF(ISNUMBER(SEARCH($J$1,$A$1:$G$1)),A8:G8),IF(ISNUMBER(SEARCH($K$1,$A$1:$G$1)),A8:G8),IF(ISNUMBER(SEARCH($L$1,$A$1:$G$1)),A8:G8))
The formula will need to be entered as an array (once copy and pasted while still in the formula bar hit CTRL+SHIFT+ENTER)
This formula works in a similar way, SUM() will add together the array values produced where IF(ISNUMBER(SEARCH() columns match the result column.
SEARCH() will return a number when it finds the exact characters in a cell which represents it's position in number of characters. By using ISNUMBER() I am avoiding having to do the whole MID() and IF(LEN()=4,""," ") I used in the previous formula as TRUE/FALSE will be produced when a match is found regardless of it's position or cell formatting.
As previously mentioned, this poses a problem as 999 can be found within 9999 etc.
The resulting array for the first part is: {250,FALSE,FALSE,FALSE,FALSE,FALSE,FALSE} (if you would like to see the array you can highlight that part of the formula and calculate with F9 but be sure to highlight the exact brackets for that part of the formula).
I hope I have explained this well, feel free to ask any questions about stuff that you don't understand. It is good to see people keen to learn and not just fishing for a fast answer. I would be more than happy to help and explain in more depth.
I start this solution with the names in an array, you can read the header names into an array with not too much difficulty.
Sub test()
Dim myArray(1 To 4) As String
myArray(1) = "/670 - White"
myArray(2) = "/650 - black"
myArray(3) = "/680 - Red"
myArray(4) = "/800 - Whitest"
For Each ArrayValue In myArray
'Find position of last character
endposition = InStr(1, ArrayValue, " - ", vbTextCompare)
'Grab the number section from the string, based on starting and ending positions
stringvalue = Mid(ArrayValue, 2, endposition - 2)
'Convert to number
NumberValue = CLng(stringvalue)
'Add to total
Total = Total + NumberValue
Next ArrayValue
'Print total
Debug.Print Total
End Sub
This will print the answer to the debug window.

Resources