I am trying to get the count of cells in a column containing dates having future date.
The column values are in string format.
I have figured out the formula as :
=COUNTIF(G19:G31,">" & TODAY())
This function works when the column values are in date format. But its failing if the cell format is in string format.
I have figured out the formula to convert a cell string value to date :
=DATEVALUE(G19)
Here are my queries:
1) How to apply DATEVALUE on a range , in this case from G19:G31?
2) How to combine these two formulas in to one single formula?
You could use:
=SUMPRODUCT(--((G19:G31+0)>TODAY()))
COUNTIF will not accept anything other than a range as its first argument so you can't use functions there.
An alternative is to write =SUM(IF(DATEVALUE(G19:G31) > TODAY(), 1, 0))
But this will be an array formula: you need to press Ctrl + Shift + Return once you've done editing, rather than just Return.
Related
I'm using a vlookup against a table that has a generally-formatted column in the format "WORD NUMBER DATE" such as "Romeo 5M 06/16/2019". The reference is a helper column that I've created combining "Romeo" and "5M" and "06/16/2019". However, the date part needs to be formatted as text or else it won't match the lookup. This formatting is causing the #N/A error, despite a match. When I use =cell=cell2, it brings up "FALSE", given the formatting.
Help with this?
Thanks in advance.
I've already tried copy/paste formatting, and typing out the text in the cell makes the reference work so I'm assuming it's the formatting.
You can format the date in three separate cells. Assuming your date is in cell A1:
In Cell B1 - get the Year value
=YEAR(A1)
In Cell C1 - change the value to 2 digits if the month value is only 1:
=IF(LEN(MONTH(A1)) = 1, "0" & MONTH(A1), MONTH(A1))
In Cell D1 - change the value to 2 digits if the day value is only 1:
=If(LEN(DAY(A1)) = 1, "0" & DAY(A1), DAY(A1))
Then, in your aggregation formula, combine them like this:
= C1 & "/" & D1 & "/" & B1
If I'm reading your question correctly this should solve your issue.
Alternatively, if you need to change the cell format to text you may need to use vba code to perform some calculations for you which I can outline for you as well if this solution doesn't help you.
I'm using COUNTIFS() formula in Excel to count number of dates in a list,corresponding to a particular name. The output values are not accurate
Formula used:
= COUNTIFS($G$31:$G$37,B32,$F$31:$F$37,"")
COUNTIFS(range1 -text, comparison value, range2-date, check for value in range 2 )
The formula first compares a list range1 (G column) with a given text comparison, then it compares the range2 (F column) list to check for a date/blank space.
I've also tried this version of formula:
= COUNTIFS($G$31:$G$37,B32,$F$31:$F$37,"?????????")
and it returns a '0' every time
Am I using this function the right way?Data Image
Looking at your provided sample data try:
=COUNTIFS($G$31:$G$37,B32,$F$31:$F$37,"<>")
In cel C32 and drag down...
It was the "<>" (anything other then empty) you were looking for I assume.
I have a table in which one column occasionally contains a sequence of numbers separated by commas (Units). I'd like to find a script that will count the amount of values in that cell (Values), then divide the adjacent cell by that amount, ultimately replacing the value of that cell (NeedResult, replacing Values).
I've played around with formulas, but my VBA skills are rudimentary... Any help mucho appreciated!
table image here
Unless you really want it, I'm not sure you need a VBA solution for this. The calculation can be done using Excel's formulas: simply subtract the length of the string from the length of it with commas removed. Your cell formula could look something like this:
=C3/(LEN(B3)-LEN(SUBSTITUTE(B3,",",""))+1)
Split the first cell value on the commas and adjust the ubound dimension of the resulting array.
dim i as long
i = ubound(split(range("b2").value, chr(44))) + 1
range("d2") = cdbl(range("c2").value / i)
Without the compiler directive Option Base 1, a split array is zero-based.
You could use a formula as well
In D2 entered as array formula with Ctrl+Shift+Enter
=IF(ISBLANK(B2),"",C2/COUNT(FILTERXML("<t><s>" & SUBSTITUTE(B2,CHAR(44), "</s><s>") & "</s></t>", "//s")))
Is there any way to make Vlookup in VBA work when 1 value is a Number and the other is a Number as Text format? I do not want to convert the format of any number.
The problem is I sometimes have reports from SAP and there the text formatted numbers are given. But i need to apply Vlookup in VBA and match in my table where numbers are number formatted. I can't convert all numbers to a number format as it takes time and I don't want to slow my macro.
It is possible with an array formula.
I assume the table from A2 to B100 and the number to match at A1
=VLOOKUP(A1,IFERROR(A2:B100*1,A2:B100),2)
This is an array formula and must be confirmed with ctrl+shift+enter.
If you are working with bigger ranges, it will be better to change to INDEX and MATCH like:
=INDEX(B2:B100,MATCH(A1,IFERROR(A2:A100*1,A2:A100),0))
This is an array formula and must be confirmed with ctrl+shift+enter.
However: if the ranges are very big, or by using whole columns, you will slow down excel a lot.
Is there any way to make Vlookup in VBA work when 1 value is a Number and the other is a Number as Text format?
An INDEX/MATCH function pair is likely the most effective method of lookup. Using IFERROR to pass the processing to an alternate MATCH seems viable.
'if the lookup 'numbers' are predominantly numeric
=index(sheet2!a:a, iferror(match(a2, sheet2!b:b, 0), match(text(a2, "0"), sheet2!b:b, 0))
'if the lookup 'numbers' are predominantly textual
=index(sheet2!a:a, iferror(match(text(a2, "0"), sheet2!b:b, 0), match(a2, sheet2!b:b, 0))
I can't convert all numbers to a number format as it takes time and I don't want to slow my macro.
A Text-to-Columns, Fixed Width, Finish converts full columns of text-that-look-like-numbers to true numbers very quickly.
Your question has no sample data or code. Please supply sample setups in future.
I post this answer as a possible simpler answer than the other two IF the text formatted numbers are the one that you are supplying as the lookup value to the Vlookup function.
Worksheet Function:
=VLOOKUP(VALUE(A1), LookupArray, 2, FALSE)
You mention in 'Vlookup in VBA' and macros, so VBA code:
retVal = Application.VLookup(CLng(lookupVal), LookupRange, 2, False)
I faced the same issue and below helped (I had SAP IDs in column 'B', replace the cell values and last row within range), this converts the SAP ID/number from General/Text/green arrowed format to numbers/values, which then can be looked up with numbers
LR1 = Sheet1.Range("B" & Rows.Count).End(xlUp).Row
With Range("B3:B" & LR1)
.Value = Evaluate(.Address & "*1")
End With
Let me know if it helped!!!
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"