Related
I have a single cell that is the output of a survey, that contains items selected from a list of 20 possible items.
ie.
Original possible selections:
Ape, Blue, Cat, Red, Dog, Yellow, Pig, Purple, Zebra
User is asked to "select all of the animals," from the list of possible selections. The output places all of the items they've identified into a single cell, separated by commas.
A new row is created for each survey entry.
ie.
| User 1 | "Ape, Cat, Pig, Purple" |
| User 2 | "Cat, Red, Dog, Pig, Zebra" |
| User 3 | "Ape, Cat, Dog, Pig, Zebra" |
etc...
I have a table with all of the animals and colors, with defined ranges.
ie. animals = A1:A5, and colours = B1:B4
I need to "score" the cell for each user, in a new cell. Where the score value is the count of the number of correctly identified items each counts as 1 point.
ie.
| User 1 | "Ape, Cat, Pig, Purple" | 3 |
| User 2 | "Cat, Red, Dog, Pig, Zebra" | 4 |
| User 3 | "Ape, Cat, Dog, Pig, Zebra" | 5 |
What would the formula need to be for that score cell for each row?
I found a previous thread, that seems to point in the right direction,
Excel: Searching for multiple terms in a cell
But this only checks for the existence of any of the items in a cell from a list and returns a true or false
Thanks for anyone's help!
COUNTIF with SUMPRODUCT:
=SUMPRODUCT(COUNTIF(D2,"*" & $A$1:$A$5 & "*"))
Which also has the limitation of the amimals not being a sub-string, like Ant and Ant-Eater
If sub-strings are a problem then use this:
=SUMPRODUCT(--(ISNUMBER(SEARCH(", " & $A$1:$A$5 & ", ",", " & D2 & ", "))))
This will make a complete match between the commas.
The formula shown is entered in D3 (an array formula, so use Ctrl+Shift+Enter) and filled down to D5
A3:A6 is a named range "animals"
Note this is only reliable if none of your terms are sub-strings of another term.
If you do not like to use the formulas above, which are very efficient and most ideal, a simpler but longer way would be as follows:
select the animals--> Data--> Text to Columns, and split them into columns with the separator being a comma
Once this is done, do a countif on each column, and it will total it up for you. You will need to do 20 countifs though, so it is far from ideal
IE
=countifs(column which it could be in],[no.1 animal])+
countifs(column which it could be in],[no.2 animal])+...
countifs(column which it could be in],[no.20 animal])
This is easy to see how it works and if you receive more answers you will have to split them out again
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.
I have a column of data with multiple value types in it. I am trying to separate out out each value type into a separate column. Below an example of the data:
6 - Cutler, Jay (Ovr: 83)
22 - Forte, Matt (Ovr: 88)
86 - Miller, Zach (Ovr: 80)
I tried to separate the data by a) going to data and clicking text to columns; however, the "Ovr: 80" portion of the data does not separate "Ovr" from 80. I also tried b) to convert to .csv file, but again was unable to separate "Ovr" from "80". Is there a formula I can use to separate this portion of the data from the rest?
I would like the data to be separated into different columns as show below:
6 | Cutler, | Jay | Ovr | 83
22 | Forte | Matt | Ovr | 88
86 | Miller | Zach | Ovr | 80
Any insight is much appreciated!
Select the cells you wish to process and run this macro to place results in the cells to the right of the selected cells:
Option Explicit
Sub dural()
Dim r As Range, s As String, ary
Dim i As Long, a
For Each r In Selection
s = r.Value
If s <> "" Then
s = Replace(Replace(s, "-", " "), ",", " ")
s = Replace(Replace(s, "(", " "), ")", " ")
s = Application.WorksheetFunction.Trim(Replace(s, ":", " "))
ary = Split(s, " ")
i = 1
For Each a In ary
r.Offset(0, i).Value = a
i = i + 1
Next a
End If
Next r
End Sub
using the method above your could do something like this...
first clean the text so its more manageable, using this formula and copying in a column you can clean it so it become a space delimited set
=SUBSTITUTE(SUBSTITUTE(SUBSTITUTE(SUBSTITUTE(SUBSTITUTE(A1,"- ",""),",",""),"(",""),")",""),":","")
from there just copy the values the formula give you to a new sheet maybe and then use 'Text To Columns to get it split into columns.
For the record I do not recommend this method if you are willing to do the text to column option.
Functions used for this solution are:
LEFT function
FIND function
MID function
for your first column of text use the following:
=left(A1,find(" ",A1))*1
That will pull out the first number presuming you do not have any leading spaces. The *1 converts from text to a number.
for your second column of last times use the following:
=MID(A1,FIND("-",A1)+2,FIND(",",A1)-(FIND("-",A1)+2))
Provided you have a coma and a dash as indicated in your example data you will not get an error and it should pull the last name without the coma.
For your third column of first names follow the same general technique as last names with the following,
=MID(A1,FIND(",",A1)+2,FIND("(",A1)-2-(FIND(",",A1)+2)+1)
Follow the similar pattern to get you over column
=MID(A1,FIND("(",A1)+1,FIND(":",A1)-1-(FIND("(",A1)+1)+1)
and finally to get your age column use this:
=MID(A1,FIND(":",A1)+2,FIND(")",A1)-1-(FIND(":",A1)+2)+1)
copy the above formulas down as far as you need to go.
I might be asking for too much here but this is also a part of the requirement that I am working on from the below excel table I would like find the value of a specified cell if I give two different values and I would like to achieve that with the OFFSET, MATCH, INDEX functions in excel.
There are two scenarios
Scenario 1:
If I give value1=3500 (which is not in the first column) and value2=75 the Result1=1.59 and Result2=1.89
Scenario 2:
If I give value1=3500 and value2=85 (both the values are not in the first row and first column of the grid) the resulting value should be Result1=1.59, Result2=1.89, Result3=1.51, Result4= 1.81`
How can I achieve this within excel?
Measure |2.5 |5 |10 |25 |50 |75 |100 |150 |200
250 |0.835 |0.75 |0.69 |0.6 |0.528 |0.455 |0.383 |0.314 |0.245
500 |1.044 |0.938 |0.863 |0.75 |0.675 |0.6 |0.525 |0.451 |0.378
1000 |1.391 |1.25 |1.15 |1 |0.923 |0.845 |0.768 |0.689 |0.61
2000 |1.948 |1.75 |1.52 |1.4 |1.321 |1.243 |1.164 |1.083 |1.002
3000 |2.435 |2.188 |1.95 |1.75 |1.67 |1.59 |1.51 |1.426 |1.343
4000 |2.853 |2.563 |2.3 |2.05 |1.97 |1.89 |1.81 |1.726 |1.643
5000 |3.507 |3.15 |2.675 |2.4 |2.269 |2.188 |2.107 |2.021 |1.936
10000 | |4.553 |4 |3.72 |3.56 |3.477 |3.394 |3.304 |3.215
15000 | |5.691 |5 |4.6 |4.469 |4.385 |4.301 |4.209 |4.117
20000 | |6.545 |5.8 |5.3 |5.151 |5.066 |4.981 |4.888 |4.795
25000 | |7.527 |6.4 |5.83 |5.666 |5.573 |5.48 |5.377 |5.274
50000 | |9.785 |8.32 |7.579 |7.366 |7.245 |7.123 |6.99 |6.856
I’ve only just noticed this problem when browsing through stackoverflow today, and since it was never actually addressed in its entirety, I’ve decided to answer it for future reference by individuals facing the same problem.
This is one of the many possible approaches to this question:
Assume the Measure table is placed in the range A1:J13 of an Excel worksheet, Value 1 is in the cell A16, Value 2 is in the cell C16 and Result values 1 to 4 are stored in the cell range E16:F17, then we can use the following formulae in Excel 2010/2013 to extract the information which you require:
In cell E16 (the cell storing the value for Result 1), enter the following formula:
=IF(AND(IFERROR(MATCH(A16,A1:A13,0),FALSE), IFERROR(MATCH(C16,A1:J1,0),FALSE)),INDEX((OFFSET($A$1:$J$13,(MATCH(A16,A1:A13,0)-1),(MATCH(C16,A1:J1,0)-1))),1,1), INDEX((OFFSET($A$1:$J$13,(MATCH(A16,A1:A13,1)-1),(MATCH(C16,A1:J1,1)-1))),1,1))
In cell E17 (the cell storing the value for Result 2), enter the following formula:
=IF((IFERROR(MATCH(A16,A1:A13,0),FALSE))," ", INDEX((OFFSET($A$1:$J$13,(MATCH(A16,A1:A13,1)),(MATCH(C16,A1:J1,1)-1))),1,1))
In cell F16 (the cell storing the value for Result 3), enter the following formula:
=IF((IFERROR(MATCH(C16,A1:J1,0),FALSE)),"",INDEX((OFFSET($A$1:$J$13,(MATCH(A16,A1:A13,1)-1),(MATCH(C16,A1:J1,1)))),1,1))
In cell F17 (the cell storing the value for Result 4), enter the following formula:
=IF(AND(IFERROR(MATCH(A16,A1:A13,0),FALSE)=FALSE, IFERROR(MATCH(C16,A1:J1,0),FALSE)=FALSE),INDEX((OFFSET($A$1:$J$13,(MATCH(A16,A1:A13,1)),(MATCH(C16,A1:J1,1)))),1,1)," ")
Assuming your workbook is placed into the named range Measure(B2:J13), Value 1(B15) and Value 2(B16), then the formulas:
=INDEX(Measure,MATCH(Value_1,$A$2:$A$13,1),MATCH(Value_2,$B$1:$J$1,1))
=INDEX(Measure,MATCH(Value_1,$A$2:$A$13,1),MATCH(Value_2,$B$1:$J$1,1)+1)
=INDEX(Measure,MATCH(Value_1,$A$2:$A$13,1)+1,MATCH(Value_2,$B$1:$J$1,1))
=INDEX(Measure,MATCH(Value_1,$A$2:$A$13,1)+1,MATCH(Value_2,$B$1:$J$1,1)+1)
will return the values you require. Use the MATCH function to select the row, selectively offset it with the + 1 (or similar) and then use INDEX to select the item in the table.
The table layout is cosmetic. Nothing prevents the column and row labels from being elsewhere entirely. The Named ranges reference the input values.
Additional input values of 1000, 10 return the results 1.15, 1, 1.52, 1.4.
In case this helps, the following formulae seem to display the values at the corners, assuming Measure is a named range starting in A1 and value1 and value2 are named ranges:
=INDEX(Measure,IFERROR(MATCH(value1,A:A,0),MATCH(value1,A:A,1)),IFERROR(MATCH(value2,1:1,0),MATCH(value2,1:1,1)))
=INDEX(Measure,IFERROR(MATCH(value1,A:A,0),MATCH(value1,A:A,1)),IFERROR(MATCH(value2,1:1,0),MATCH(value2,1:1,1)+1))
=INDEX(Measure,IFERROR(MATCH(value1,A:A,0),MATCH(value1,A:A,1)+1),IFERROR(MATCH(value2,1:1,0),MATCH(value2,1:1,1)))
=INDEX(Measure,IFERROR(MATCH(value1,A:A,0),MATCH(value1,A:A,1)+1),IFERROR(MATCH(value2,1:1,0),MATCH(value2,1:1,1)+1))
Not exactly what you want but here is my try:
Enter following formula for B19, then copy&paste to all cell in green table.
=IF(OR(AND($B$15=$A19,$B$16=B$18),AND($B$15>$A18,$B$15<$A20,$B$16>A$18,$B$16<C$18)),B2,0)
I have an Excel spreadsheet of data like:
ColumnA ColumnB
33 11
25 5
6 4
What i would like to do is add a third column which shows the ratio of columnA to columnB in the format of A:B. For example:
ColumnA ColumnB Ratio
33 11 3:1
25 5 5:1
6 4 3:2
How can this be done?
Try this formula:
=SUBSTITUTE(TEXT(A1/B1,"?/?"),"/",":")
Result:
A B C
33 11 3:1
25 5 5:1
6 4 3:2
Explanation:
TEXT(A1/B1,"?/?") turns A/B into an improper fraction
SUBSTITUTE(...) replaces the "/" in the fraction with a colon
This doesn't require any special toolkits or macros. The only downside might be that the result is considered text--not a number--so you can easily use it for further calculations.
Note: as #Robin Day suggested, increase the number of question marks (?) as desired to reduce rounding (thanks Robin!).
You are looking for the greatest common divisor (GCD).
You can calculate it recursively in VBA, like this:
Function GCD(numerator As Integer, denominator As Integer)
If denominator = 0 Then
GCD = numerator
Else
GCD = GCD(denominator, numerator Mod denominator)
End If
End Function
And use it in your sheet like this:
ColumnA ColumnB ColumnC
1 33 11 =A1/GCD(A1; B1) & ":" & B1/GCD(A1; B1)
2 25 5 =A2/GCD(A2; B2) & ":" & B2/GCD(A2; B2)
It is recommendable to store the result of the function call in a hidden column and use this result to avoid calling the function twice per row:
ColumnA ColumnB ColumnC ColumnD
1 33 11 =GCD(A1; B1) =A1/C1 & ":" & B1/C1
2 25 5 =GCD(A2; B2) =A2/C2 & ":" & B2/C2
The second formula on that page uses the GCD function of the Analysis ToolPak, you can add it from Tools > Add-Ins.
=A1/GCD(A1,B1)&":"&B1/GCD(A1,B1)
This is a more mathematical formula rather than a text manipulation based on.
Below is the formula I use. I had a problem using GCD, because I use fairly large numbers to calculate the ratios from, and I found ratios such as "209:1024" to be less useful than simply rounding so it displays either "1:" or ":1". I also prefer not to use macros, if at all possible. Below is the result.
=IF(A1>B1,((ROUND(A1/B1,0))&":"&(B1/B1)),((A1/A1)&":"&(ROUND(B1/A1,0))))
Some of the formula is unnecessary (e.g., "A1/A1"), but I included it to show the logic behind it. Also, you can toggle how much rounding occurs by playing with the setting on each ROUND function.
Lets assume you have data in D and E cells..
Here is an easiest ratio displaying fn by my frnd 'Karthik'
=ROUND(D7/E7, 2) &":" & (E7/E7)
At work we only have Excel 2003 available and these two formulas seem to work perfectly for me:
=(ROUND(SUM(B3/C3),0))&":1"
or
=B3/GCD(B3,C3)&":"&C3/GCD(B3,C3)
I found this to be the easiest and the shortest, I however rounded off to zero decimal places:
="1" & ":" & ROUND((A1/B1),0)
Note the spaces before and after &.
What this means is that "1" and ":" are seen as additional non-formula information to the overall formula. The ROUND function rounds off A1/B1 that is the basic formula to 0 decimal places. you can try changing to 1,2,3... decimal places.
I hope I made this clear.
Thanks ya'll. I used this:
=CONCATENATE((number1/GCD(number1,number2)),":",((number2/GCD(number1,number2))))
If you've got 2007 this works great.