Get cell to the right of current month in Excel - excel

I'm pretty new to Excel, that question is probably easy, but I dont know what to do :-(.
So this is what I have:
Date Numbers
01.09.11 10
01.10.11 20
01.11.11 30
01.12.11 40
Now what I want is in another cell: Get the number of the date, where the date's month is the current month. How do I do this?

Assuming all your dates are strings of the form "dd.mm.yy", you can use the following array formula:
=INDEX(B1:B4,MATCH(9,VALUE(MID(A1:A4,4,2)),0))
where the 9 is the month number you want to look up. Enter this as an array formula by pressing Ctrl+Shift+Enter.
EDIT:
As pointed out in the comments, you want to match the current month, so incorporating #JMax's suggestion works:
=INDEX(B1:B4,MATCH(MONTH(TODAY()),VALUE(MID(A1:A4,4,2)),0))
To clear up any confusion, MID() returns a string, which by itself will not return a match for the number value returned by MONTH(TODAY()). However, if you stick the MID() function inside a VALUE() function, the string returned by MID() will be converted into a number value. E.g., "09" becomes the number 9, "10" becomes the number 10. This allows you to match the number value returned by MONTH(TODAY()).
However, if your dates are entered as dates with format dd.mm.yy in your sheet instead of as strings, then you can use the same strategy but with a different matching term:
=INDEX(B1:B4,MATCH(MONTH(TODAY()),MONTH(A1:A4),0))
Enter this as an array formula.

Related

Timevalue function not working for unrecognized time format

I have a bunch of time data that's formated weirdly, ranging from numbers 100 (representing 1 AM, or 01.00.00) to 2359 (representing 11.59PM, or 23.59.00).
I have been trying to use the TIMEVALUE() function to convert these data, but it just returns #Value?, I guess because the time format 'HHMM' is not recognized without the ' : ' separating them?
What I'd like is to convert it to the HH:MM:SS format, where the SS would automatically be zero.
Use REPLACE:
=--REPLACE(A1,LEN(A1)-1,0,":")
Then format it as desired.
If your text values are consistent, this can be carried out by using a formula that splits the value by the number of characters and then recombines the split values into a time value.
All formulas assume that your weirdly formatted text value is in cell B2
=IF(LEN(B2)>3,LEFT(B2,2),LEFT(B2,1))
This formula works out the first (hour) element of a time, if the text string is greater than three characters it will take the first 2 characters of the string (23), if its less than 3 characters it will only take the first character (1)
=RIGHT(B2,2)
This formula takes the second (minute) element of the time.
=TIME(C2,D2,0)
Finally this formula converts the two text elements into a string
C2 = The cell with formula 1 in it
D2 = The cell with formula 2 in it
This could all be written as the following formula if needed
=TIME(IF(LEN(B2)>3,LEFT(B2,2),LEFT(B2,1)),RIGHT(B2,2),0)

Given a value in an table of values in Excel, how to return the corresponding value from the first column/row

I have the following data-set:
Given a number that occurs only once in the data range B2:E5, I would like to use a formula that returns the corresponding date value. The date values are given in the first column (A2:A5). I would also like to be able to return the corresponding hour value using a similar formula. Note, it is not necessary to return the hour and the date for a given value using the same formula.
Example: In the image of the data-set above – given the number 5, I would like to return the corresponding date. In this case, the formula would return the date value 03/01/2013. Similarly, I would also like to be able to return the "hour 3", given the same initial value.
Maybe the answer to this question is quite straight forward, but as of yet I have had no luck in figuring it out. Some things that I have tried, but to no avail, are the following: VLOOKUP/HLOOKUP, LOOKUP, a combination of INDEX+MATCH, and a combination of INDEX+MATCH+MATCH.
Any help is very much appreciated.
Given that Number to Find is unique, you can use this:
For the date in Column 1
=INDEX(Table1[Column1],MAX((NumToFind=Table1 )*ROW(Table1 ))-1)
For the hour in the Headers fields:
=INDEX(Table1[#Headers],1,MAX((NumToFind=Table1)*COLUMN(Table1)))
The above formulas are array formulas and must be confirmed by holding down CTRL + SHIFT ENTER
The -1 in the first formula is to compensate for the fact that the table starts in Row 1, with the data starting in Row 2, and the formula determines the absolute row number; if it starts other than in A1, different compensating values will be required.

Excel Formula get numbers from cell using mid and convert to date?

I have a 12 digit number in column A like so:
Column A
041120121601
Within this number there is a date 201216 or 20/12/16.
I am trying to get the date from the number using mid:
=MID(B8,5,6)
I now get this as a result: 201216.
I am trying to format this as a date like this:
20/12/2016
Here's what i've tried:
=TEXT(D8, "00-00-00")
This gives me this:
20-12-16
This is close, but i need it to be 20/12/16
OK, if it starts with a 0, Excel doesn't think this is a number. It thinks it's text. This is important, because one day someone will copy and paste the input data and Excel will automagically convert them to numbers and your formulas all
will break because the leading 0 is missing now.
So, let's first convert the cell into a number, then back into text with "000000000000" format:
=Text(Value(A1),"000000000000")
Then apply the DateValue formula with three Mid functions as Tim describes.
(Or your input data are numbers in "000000000000" format, but that's a little unusual.)
You can your split MID and force a date separator betwixt each number and wrap it in DATEVALUE, then just format as a date.
=DATEVALUE(MID(B8,5,2)&"/"&MID(B8,7,2)&"/"&MID(B8,9,2))
If it's always the same amount of characters then =MID(TRIM(A1),4,2)& "/" & MID(TRIM(A1),6,2) & "/" & MID(TRIM(A1),8,2)

Identifying date in text file While date is incorrectly formatted

I need to extract the date from C2 and find the difference between the date in c2 and A1
The date is formatted as "Jul, 18 2015", any ideas? EDIT the database has a different amount of text per cell. Is there away around this so that i can apply the formula to every cell and pull the day/month/year?
you are going to need to go through a series of string manipulation and date time functions. Lets start by assuming your string is in the C2 cell. In order to do this we are going to work from the largest unit (years) to the smallest unit (days). You can do it in any order as it will all be lumped into once formula, but for the breakdown of steps its good to have an order.
Step 1) PULL OUT THE YEAR
=MID(C2,FIND(" ",C2,FIND(" ",C2)+1)+1,4)
That will give us the last 4 characters of the string after the second space which in this case is the year.
Step 2) PULL OUT THE MONTH
=MONTH(DATEVALUE(MID(C2,2,3)&"-"&1))
that looks at second character and pulls out the string 3 character long which is your month. It then converts it to a format that excel tends to recognize as a date short form by adding a - and the digit 1 to it. So in your case if would look like Jul-1. Datevalue converts this to an excel date serial, which we then pull back and grab the month from and in your case that is 7
If the above formula does not work for you it could be due to regional settings. If that is the case you can use the following:
=MATCH(MID(C2,2,3),{"Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"},0)
If you use this alternat formula , be sure to adjust the final equation accordingly.
Step 3) PULL OUT THE DAY
=TRIM(MID(C2,FIND(" ",C2)+1,2))
So the above formula finds the first space and then starts pulling then next 2 characters after it. Now since I do not know if the first of the month is 01 or just 1, it may wind up grabbing the space after the 1. The trim function removes excess spaces.
Step 4) BUILD THE DATE
The DATE function in excel requires the YEAR, MONTH, and DAY and converts those values in to the excel date serial. In this case we will convert:
=DATE(year,month,day)
to the following by substituting our equations from above:
=DATE(MID(C2,FIND(" ",C2,FIND(" ",C2)+1)+1,4),MONTH(DATEVALUE(MID(C2,2,3)&"-"&1)),TRIM(MID(C2,FIND(" ",C2)+1,2)))
The final touch is to ensure your cell is formatted as date and not General or some other format which will result as the date being displayed in an integer format.
Now assuming you date in A1 is in Excel format, you would simply add A1- to the front of the last formula to give you:
=A1-DATE(MID(C2,FIND(" ",C2,FIND(" ",C2)+1)+1,4),MONTH(DATEVALUE(MID(C2,2,3)&"-"&1)),TRIM(MID(C2,FIND(" ",C2)+1,2)))
Now, if A1 is also in quotes like the C2 formula, repeat the formula for stripping the date out of C2 but use A1 as the reference and substitute it in for A1 in the last formula to give:
=DATE(MID(A1,FIND(" ",A1,FIND(" ",A1)+1)+1,4),MONTH(DATEVALUE(MID(A1,2,3)&"-"&1)),TRIM(MID(A1,FIND(" ",A1)+1,2)))-DATE(MID(C2,FIND(" ",C2,FIND(" ",C2)+1)+1,4),MONTH(DATEVALUE(MID(C2,2,3)&"-"&1)),TRIM(MID(C2,FIND(" ",C2)+1,2)))
FORMULAS USED
Text/String Functions
MID
FIND
TRIM
Date/Time Functions
DATE
DATEVALUE
MONTH

Count date field that occurs in a specific month

I need to count the occurrence of a specified month in my data, I used the following formula
=SUMPRODUCT((MONTH(E$2:E$9999)=2)*(YEAR(E$2:E$9999)=2011)*1)
The formula works, but XCelsius do not recognize the SUMPRODUCT function
This is my data sample
2011/02/14 08:54:21 AM
2011/02/18 11:08:57 AM
2011/02/21 10:40:55 AM
2011/04/13 09:48:46 AM
2011/04/14 09:03:58 AM
2011/05/25 06:20:29 AM
Is there another way of counting the occurrences of a specified month
Maybe try this:
=COUNTIF(E$2:E$9999,">=2011-02-01")-COUNTIF(E$2:E$9999,">=2011-03-01")

Resources