I'm wondering if there's a shortcut to the following.
I have a product form that customers will fill out and I need the formula to format the part numbers they enter correctly. If it doesn't their entry doesn't match the products list.
Below are the variety of text/number/other variations...
Excel Columns/ Rows Example
101
7-2009
7-5601-RT
G-2121
5728B
PI-PIXES
I got all but the last one working with this formula:
FORMULA1
=AND(SUMPRODUCT(--ISNUMBER(--MID(B40,ROW($1:$9996),1)))<LEN(B40),MIN(FIND({0,1,2,3,4,5,6,7,8,9},B40&"0123456789"))<=LEN(B40))
I also have to keep it in .xls format.
Basically, I have one column that checks this above and it returns TRUE/FALSE.
I have another formula that checks for text:
FORMULA2:
=IF(I40=FALSE,"NUMBER", "TEXT")
The final column TESTS FOR TEXT/NUMBER.
FORMULA3:
=IF(J40 = "NUMBER", VALUE(B40), B40)
PI-PIXES is flagged as number because of the dash(hyphen).
Without any other option, I'm considering adding a third column to find TEXT with hyphens. I would then change FORMULA3 check if both if column 1 = TRUE+column 2 = TRUE and column 3 = TEXT but this is getting complicated and I'm wondering if there's a shortcut.
I think this does it:
=IF(SUBSTITUTE(B40,"-","")<>TEXT(B40,"#"),B40,IFERROR(VALUE(B40),B40))
If there are hyphens, it returns the B40 unchanged, eliminating dates. Otherwise, it handles it as a normal Value conversion with IFERROR.
This should work for older versions of Excel:
=IF(SUBSTITUTE(B40,"-","")<>TEXT(B40,"#"),B40,IF(ISERR(VALUE(B40)),B40,VALUE(B40)))
Or even this:
=IF(ISERR(FIND("-",B40)),IF(ISERR(VALUE(B40)),B40,VALUE(B40)),B40)
Related
This is the problem i am facing in Excel formula
enter image description here
In column F, i want to find the common text across A2 to E2 (containing Blanks)
My Question:
Is there a simple way to get the result without VB?
Any help is appreciated,thanks
I found that google sheets has some really cool functions.
If you put the formula =SPLIT(A1, ",", TRUE,FALSE) in the cell after your row of common text (or probably even in a different sheet - "probably because hadn't tried it, though it should), the next x cells (where x is the number of "," in A1 - because "," is the delimitator) will be the text.
then you can put the code =IF(SUM(ARRAYFORMULA(if(REGEXMATCH($A$1:$D$1,F1),1,0)))=COUNTA($A$1:$D$1),F1,"") into an equal number of cells after that (probably should just put into the max number), and =CONCATENATE(I1:L1) into the last cell.
Ok. So to tweak this for yourself: I found that ARRAYFORMULA lets you put an array in place of a single cell in a function inside. how it exactly works I read its like a for loop. but I can't really vouch for that. but here it lets you have REGEXMATCH (which is a Boolean check on the cell you give it for if it contains the given REGEX) check each cell in the array.
the sum will add them up, and the if will match against the COUNTA to find if the number of cells in the array that contain this string is equal to the number of non-empty cells.
the concatenate at the end adds all the cells (containing the regex function) together, and since the only non-empty cells will be the one with the string, that is what this cell will return (no spaces).
code:
results:
the test data:
If you need in specifically Excel... this won't help.
We can use power query to achieve the desired result.
Unpivot the columns in Power query
Split all the columns by Comma delimiter
Create a custom column to see if the first column records exist in the remaining columns.
Use the functionText.contains.
Sample function: =Text.Contains([column.1],[column.1]&[column.2]&[column.3])
If the above function returns TRUE then get the first column result(This is the expected result) and load the data back to your excel
=(Countifs(B:B;”*”;F:F;”<>*1”))
Why doesn't this work?
I want to count all the rows in the sheet, except the ones that has a number that ends with 1 in column F. It just count all the rows, even the ones in column F that ends with 1.
How do I exclude those?
edit
Some more information!
This is a sample of the data:
Could be up to 8000 rows some days. Column B always says "Independent instruction" so I'm using that as a base to count all the rows. Column F contain only numbers, or blank cells (meaning a number will be added later). I still want to count those rows as well (that's blank). It's just the rows that has a number in column F that ends with 1 that I want to exclude!
SUMPRODUCT gives a bit more flexibility for criteria that involve more than straightforward string-matching:
=SUMPRODUCT(--(LEN($B:$B)>0),--(RIGHT($F:$F,1)<>"1"))
The array formula:
{=COUNT(IF((F:F<>"")*(MOD(F:F;10)<>1);F:F))}
will count all non empty cells in the conditions of your question.
Don't forget to press Ctrl+Shift+Enter to place the formula.
Why doesn't this work?
Apart from the fact that you have transcribed it incorrectly (i.e. missing =, and smart quotes ”) the 'F' condition in quotes is a Text value, a formatting issue #BigBen has mentioned in connection with the 'B' values.
You say It just count all the rows so, syntactically corrected, your formula must be working on (a) all 'B's populated (with Text) and (b) all 'F's Numeric. As 1 and "1" are not the same, none of your entries in ColumnF will be excluded by your attempt (none end in "1", though presumably some do end in 1).
#Pspl's A works because its condition (for the 'F's) is based on MOD (applies to Number format values) and #jsheeran's A (my preference) because RIGHT is a string function that returns Text format even from a Number format value.
Put another way, with say 1 in F1, =F1="1" returns FALSE (so =F1<>"1" and =F1<>"*1" return TRUE - that would not suit you) whereas =RIGHT(F1)="1" returns TRUE (or, to suit you, RIGHT(F1)<>"1" returns FALSE).
You can try to use a combination of SUM and IF. Remember to adjust the formula to match your Excel formatting, i.e. replace commas (,) with semicolon (;).
This is an array formula (enter with Ctrl+Shift+Enter)
=SUM(IF(MOD($F$2:$F$25,10)<>1,1,0))
Result (updated with your data set):
When pasting the image into merged cells, the error looks like that:
So you need to make sure the formula is pasted into a single (not merged) cell.
Array formula for values greater than 1000:
=SUM(IF((MOD($F$2:$F$25,10)<>1)*($F$2:$F$25>1000),1,0))
Array formula for values less than 1000:
=SUM(IF((MOD($F$2:$F$25,10)<>1)*($F$2:$F$25<1000),1,0))
Example:
On Sheet 1, I have a master list of data, with corresponding attributes. Some data has more than one attribute, some has only one, and there is a possibility of blanks. Attributes can be repeated when assigned to a different name.
I've posted some example data below, so we can all talk about the same cells/names etc.
On Sheet 2, there is much more freeform data input/analysis going on. Users are able to select a 'Name' from a dropdown menu using Data Validation, and are then able to select from the available attributes corresponding to that name, again using a dropdown menu. Names and attributes can appear in any order on Sheet 2.
It is important that all pairings are considered in the second worksheet.
Is it possible to use conditional formatting to highlight the 'Name' field (on Sheet 2) until at least one row exists with all possible pairings? In the example below, you can see that we have forgotten to put any info relating to the fact that Sally is Happy, and consequently 'Sally' has been highlighted to draw attention to the fact that there is some missing information.
Current thoughts:
I already have a list of the attributes that match the corresponding name- this is what drives the dropdown menu on Sheet 2, and is generated in a background sheet when a name is picked on Sheet 2. I can count the non-blank cells in this range to find out the total number of pairs that are required.
I would like to then count the number of non-duplicate attributes that are on rows that have the same Name as the current row, and compare this value.
I'm expecting this to get into the realms of array formulae, but may be wrong...
I'm also expecting array formulae to not work directly with conditional formatting, and to require the use of a 'helper column' to drive the formatting. Let me know if this is incorrect?
Something along the lines of the below (formatted as pseudo-code for readability, but this should be read as a high level description, not actual code)
{Count the 1s in the array(AND(
'Check if it's a name match'
If($D$1:$D$10=[$ACurrent],[set flag to 1],[set flag to 0])
'Check if it's a unique value'
[somehow check array values set at 1 to see if there is a duplicate value in column E, and then set the array value to zero if so])
}
Does this approach make sense, and how would I go about constructing this actual formula?
I don't mind using VBA if required, but would prefer to avoid it if possible (company policy, sorry).
Well, you want to highlight value Sally, Happy if that value does not appear in Sheet2, so you just need a COUNTIFS
COUNTIFS function
I've got this:
I've used a Conditional Formatin Rule based on my own formula. The formula I've used is:
=IF($B2="";IF(COUNTIFS($F$2:$F$12;$A2;$G$2:$G$12;"")=0;TRUE;FALSE);IF(COUNTIFS($F$2:$F$12;$A2;$G$2:$G$12;$B2)=0;TRUE;FALSE))
There are 2 COUNTIFS, because blank values are possible:
IF(COUNTIFS($F$2:$F$12;$A2;$G$2:$G$12;"")=0;TRUE;FALSE) will count how many rows got same name and non blank attributes in Sheet2. If 0, then it will return True and highlight row.
IF(COUNTIFS($F$2:$F$12;$A2;$G$2:$G$12;$B2)=0;TRUE;FALSE) will count how many rows got same name and blank attributes. If 0, then it will return True and will highlight
With the initial IF you can blanks or non blanks attributes, just to make sure you count all posibilities of values.
I've uploaded a sample to mi Gdrive in case you want to download and get the formulas autotranslated opening at your PC.
https://drive.google.com/open?id=1Im4LoaK4EIvINBj7tfyEcYk9juWUp7zr
Hope you can adapt this to your needs.
#Foxfire And Burns And Burns helped me to solve my problem - I have modified his formulae slightly, to remove the double COUNTIFS, and to account for rows in the master data where both cells are blank - below is what I used.
=IF (OR($A2<>"",$B2<>""),
(IF(COUNTIFS($D$2:$D$12,$A2,$E$2:$E$12,IF($B2="","",$B2))=0,TRUE,FALSE)
)
)
This works by returning TRUE or FALSE from the following logical checks - if the final result is TRUE, then the formatting appears.
OR($A2<>"",$B2<>"") - Checks is either of the cells in the master are not blank. - If both cells are blank, this returns FALSE, and does not format anything (see A10:B10).
IF(COUNTIFS($D$2:$D$12,$A2,$E$2:$E$12,[see point 3])<1,TRUE,FALSE) - This counts the number of times that both the range $D$2:$D$12 contains the value of cell $A2, AND the range $E$2:$E$12 contains the value of cell $B2. If that number is <1, (zero matches), then the statement returns TRUE and implements the formatting.
IF($B2="","",$B2) - This nested IF statement checks if Cell $B2 is blank, and returns "" if it is blank, or keeps the value of $B2 otherwise. This is because COUNTIFS would see the cell as a 'zero' when blank otherwise (see A9:B9).
I have not used a similar nested if to check if $A2 is blank, because it should not be blank, so it's useful to highlight that the user has made an error in data entry here, too (see A2:B2 - this will remain red once the user inputs a name, as it will no longer match D2:E2.)
Reference image below:
I am trying to get some code working but when I change a target cell into a range of cells I get an error #VALUE!
this code works
=IF(AND(A1=Sheet2!A2,B1=Sheet2!B2),"TRUE","FALSE")
but if I add a range I get #VALUE! Error
=IF(AND(A1=Sheet2!A2:A10,B1=Sheet2!B2:B10),"TRUE","FALSE")
Update : Here is an example of what I am trying to achieve
Any help would be much appreciated
Many Thanks,
And
Different approach from your logic statement. Instead it looks through your table and match the name with the row and the column with the date selected and the pulls the value at that location.
=INDEX($B$7:$G$8,MATCH($B3,$A$7:$A$8,0),MATCH(C$1,$B$6:$G$6,0))
IMPORTANT: The names in you B3:B4 area have to be unique and spelled identical to your A7:A8 area. That included trailing or leading spaces that you may accidentally drop in.
Adjust reference ranges to match your need if tables are on different sheets of your workbook.
THIS IS AN ARRAY FORMULA - Hit Ctrl+Shift+Enter While still in the formula bar
=INDEX(B2:B10,SMALL(IF(A2:A10=A1,IF(B2:B10="ONCALL",ROW(A2:A10)-1)),1))
=INDEX(B2:B10, - Look through B2:B10 and return the row number calulcaulated by:
SMALL(IF(A2:A10=A1,
IF(B2:B10="ONCALL",
ROW(A2:A10)-1)),1))
This is building an array of row numbers minus 1 where both IF statements are true (Date matches and "ONCALL" present), SMALL then returns the nth value in ascending order - I have asked for the 1st match (or the smallest row number) which INDEX then uses to return the result.
I have an Excel formula reading data from a column. The data in that column is sometimes a date-like format, such as "10-11". Despite the fact that I've ensured that column is text formatted -- and all values display correctly as plain text, not reinterpreted as dates -- the formula is basically reinterpreting them as dates in the reference.
I need a way to force the formula's cell reference to interpret the cell as text. I tried TEXT(A1, "#") but it doesn't work -- it gives the numeric value of the date.
Brian Camire's answer explains why, but here's a worksheet function that will work for you. Note that you have to create that numeric array in it based on how long the longest string will be. It's an array formula, so when you first enter it you have to hit CTRL-SHIFT-ENTER, then you can click and drag it down the column.
=LEFT(A1, MATCH(FALSE, ISNUMBER(VALUE(MID(A1, {1,2,3,4,5}, 1))),0) - 1)
Short answer: When referring to number-like (or date-like) text values in a formula, don't use them in a place in the formula where Excel is expecting a number.
Long answer: Even if the source column is formatted as text and the values in the source column are truly entered as text (and not numbers, including dates), Excel may automatically convert text values to numbers (including dates) when you reference them in a formula if you use them in a place where Excel is expecting a number (or date).
For example (assuming US date formats), in a blank worksheet:
Set the format for column A to Text.
In cell A1, enter the value 10-11.
In cell B1, enter the formula =T(A1). The T() worksheet function returns the supplied value if it is text. Otherwise, it returns an empty string. The result of the formula in cell B1 should be 10-11, indicating that the value of A1 is text, not a number or date (in which case the result would be an empty string).
In cell C1, enter the formula =A1.
In cell D1, enter the formula =T(C1). The result should also be 10-11, indicating that the value of the formula in C1 is text, not a number or date. This shows that you can (sometimes) use a text value that looks like a number (or date) in a formula and have Excel treat it as text (which is what you want).
In cell E1, enter the formula =A1+0. The result will be 40827. This is the numeric value of the date October 11, 2011. This shows that you can (sometimes) use a text value that looks like a number (or date) in a formula and Excel will automatically convert it to a number (which is what you observed) if you use it in a place (like on either side of the + operator) where Excel is expecting a number.
To insert a value into a cell and have it not be auto-formatted, and just treated as text, you can enter it like this:
=("cell data")
eg:
=("+1 3456789")
When you use &"", Excel converts the results of a formula to text (like *1 would convert to numbers).
Thus, you can use this formula:
=TEXT(A1;"jj-mm")&""
If you put a single quote in front of the text in the cell, it should be represented as text on all references:
'10-11
Just add zero to the input!
I was having a similar problem where I had a list of numbers with a text prefix (like FOO-1, FOO-25, FOO-979) but I just wanted the number part (1, 25, 979) so I could run another formula off of that. I was using SUBSTITUTE to replace the text portion with blank, but my other formula using these numbers was coming up with bogus results. I ended up making my formula like this:
=SUBSTITUTE(B1:B10,"FOO-","")+0, and now the ISNUMBER is saying TRUE where before it was saying FALSE.
In my case, I have a form worksheet that is used by dealers to ad parts and have it calculate the final cost; it references a locked "products" sheet. The problem is that I had no way of controlling what they entered.
Products can be like:
101 = A true number
7-2009 = Reads as date
7-5601-RT = TEXT/NUMBER reads as both number or text (NOT SOLVED YET)
CP6072CD = reads as plain text
I have most of this figured out; the only one that isn't is the one that reads as both text/Number.
In case anyone is looking for a similar solution, i did the following:
I created three additional columns to test and display the three different cases: "NUMBER", "DATE" , "TEXT".
DATE: =NOT(ISERROR(DATEVALUE(B42)))
ISOTHER: =(ISNUMBER(--(MID(B42,ROW(INDIRECT("1:"&LEN(B42))),1))))
NUMBER: =ISNUMBER(B42)
NUMBER/TEXT: =NOT SOLVED YET
I42 = DATE
J42 = NUMBER
K42 = OTHER
L42 = TEXT
M42 = THE RESULT OF THE QUERY BELOW
=IF(AND(I42 = FALSE, J42 = FALSE, K42 = TRUE), "NUMBER", IF(AND( I42 = TRUE, J42= FALSE, K42=TRUE), "DATE", "TEXT"))
This (ABOVE) tests all the true/false results and depending on what the value turns out to be, I format each of them using:
ISNUMBER = VALUE(B42)
DATE FORMATTED AS B42*1
ELSE TEXT - AS ORIGINAL
=IF(M42 = "NUMBER", VALUE(B42), IF(M42 = "DATE", B42*1, B42))
So now I just need to figure out how to test if something is both text and number because the 7-5601-RT tests out as the same as number: "FALSE, FALSE, TRUE, TRUE"