Excel Formula Bible : Part 1
These formulas and explanations may change according to the updates of the excel application, please check for the same.
1. SUM of Digits when cell Contains all Numbers
If you cell contains only numbers like A1:= 7654045, then following formula can be used to find sum of digits
=SUM(--MID(A1,SEQUENCE(LEN(A1)),1))
=SUMPRODUCT(--MID(A1,ROW(INDIRECT("1:"&LEN(A1))),1))
=SUM(--MID(A1,ROW(INDIRECT("1:"&LEN(A1))),1))
If A1 is blank, then to handle error, you can enclose above formulas into an IFERROR block.
2. SUM of Digits when cell Contains Numbers and non Numbers both
If your cell contains non numbers apart from numbers like A1:= 76$5a4b045%d, then following formulas can be used to find sum of digits
=SUM(IFERROR(--MID(A1,SEQUENCE(LEN(A1)),1),0))
=SUMPRODUCT((LEN(A1)-LEN(SUBSTITUTE(A1,ROW($1:$9),"")))*ROW($1:$9))
=SUM(IFERROR(--MID(A1,ROW(INDIRECT("1:"&LEN(A1))),1),0))
3. A List is Unique or Not (Whether it has duplicates)
Assuming, your list is in A1 to A1000. Use following formula to know if list is unique.
=MAX(COUNTIF(A1:A1000,A1:A1000))
If answer is 1, then it is Unique. If answer is more than 1, it is not unique.
4. Count No. of Unique Values
Use following formula to count no. of unique values -
=IF(COUNTA(A1:A100)=0,0,COUNTA(UNIQUE(FILTER(A1:A100&"",A1:A100<>""))))
=SUMPRODUCT((A1:A100<>"")/COUNTIF(A1:A100,A1:A100&""))
=SUM((A1:A100<>"")/COUNTIF(A1:A100,A1:A100&""))
5. Count No. of Unique Values Conditionally
If you have data like below and you want to find the unique count for Region = “A", then you can use below formula –
=SUM(IF(FREQUENCY(IF(A2:A20<>"",IF(A2:A20="A",MATCH(B2:B20,B2:B20,0))),ROW(A 2:A20)-ROW(A2)+1),1))
If you have more number of conditions, the same can be built after A2:A20 = “A".
6. Generate Sequential Weekday names like Sun, Mon, Tue, .....,Sat
For 3 characters Weekday name
=TEXT(DATE(2017,1,SEQUENCE(7)),"ddd")
=TEXT(DATE(2017,1,ROW($1:$7)),"ddd")
(Note – Year 2017 has been used as 1-Jan-2017 was Sunday. You can use any year in place of 2017 where 1-Jan was a Sunday like year 2023)
For full Weekday name, replace ddd with dddd
=TEXT(DATE(2017,1,SEQUENCE(7)),"dddd")
=TEXT(DATE(2017,1,ROW($1:$7)),"dddd")
You can add a number if you want to show some other Weekday Name. Say, if you want to
show 1 = Monday, 2 = Tuesday…….7 = Sunday, just add 1 . Hence, formulas would become
=TEXT(1+DATE(2017,1,SEQUENCE(7)),"ddd")
=TEXT(1+DATE(2017,1,ROW($1:$7)),"ddd")
The above formulas will generate the sequence in a column. If you want to generate in a row, use following formulas
=TEXT(DATE(2017,1,SEQUENCE(,7)),"ddd")
=TRANSPOSE(TEXT(DATE(2017,1,ROW($1:$7)),"ddd"))
7. Generate Sequential Month names like Jan, Feb, Mar. Dec
Generate 3 characters month names
=TEXT(DATE(1,SEQUENCE(12),1),"mmm")
=TEXT(DATE(1,ROW($1:$12),1),"mmm")
For full month name, replace mmm with mmmm
=TEXT(DATE(1,SEQUENCE(12),1),"mmmm")
=TEXT(DATE(1,ROW($1:$12),1),"mmmm")
The above formulas will generate the months names in a column. To generate in a row –
=TEXT(DATE(1,SEQUENCE(,12),1),"mmm")
=TRANSPOSE(TEXT(DATE(1,ROW($1:$12),1),"mmm"))
8. Find Last Day of the Month
Suppose, you have a date in the cell A1≔ 14-Aug-22, then formula for finding last day of the month is
=EOMONTH(A1,0)
9. Number of Days in a Month
Suppose, you have been given a date say 15-Nov-21 and you have to determine how many days this particular month contains.
The formula which you need to use in the above case would be
=DAY(EOMONTH(A1,0))
10. Find First Day of the Month
Suppose, you have a date in the cell A1≔ 14-Aug-21, then formula for finding first day of the month is
=A1-DAY(A1)+1
=EOMONTH(A1,-1)+1
=DATE(YEAR(A1),MONTH(A1),1)
11. Add Month to or Subtract Month from a Given Date
Very often, you will have business problems where you have to add or subtract month from a given date. One scenario is calculation for EMI Date.
Say, you have a date of 10/22/21 (MM/DD/YY) in A1 and you want to add number of months which is contained in Cell B1.
The formula in this case would be
=EDATE(A1,B1)
[Secondary formula =DATE(YEAR(A1),MONTH(A1)+B1,DAY(A1)) ]
Now, you want to subtract month which is contained in Cell B1.
=EDATE(A1,-B1)
[Secondary formula =DATE(YEAR(A1),MONTH(A1)-B1,DAY(A1)) ]
12. Add Year to or Subtract Year from a Given Date
In many business problems, you might encounter situations where you will need to add or subtract years from a given date.
Let's say A1 contains Date and B1 contains numbers of years. If you want to add Years to a given date, formulas would be -
=EDATE(A1,12*B1)
=DATE(YEAR(A1)+B1,MONTH(A1),DAY(A1))
If you want to subtract Years from a given date, formulas would be -
=EDATE(A1,-12*B1)
=DATE(YEAR(A1)-B1,MONTH(A1),DAY(A1))
13. Convert a Number to a Month Name
Use below formula to generate named 3 lettered month like Jan, Feb Dec
=TEXT(A1*30,"mmm")
Replace "mmm" with "mmmm" to generate full name of the month like January, February December in any of the formulas in this post.
14. Convert a Month Name to Number
Say Cell A1 contains the string January, February….December (or Jan. Feb Dec) and you
want to show 1, 2 12
=MONTH("1"&A1)
The formula would work as long as month names are >=3 characters. Hence, it would work for say Janu or Decem or Apri or Octobe.
15. Convert a Number to Weekday Name
Suppose you want to return 1 = Sunday, 2 = Monday… 7 = Saturday
=TEXT(DATE(2017,1,A1),"dddd")
Note – 2017 has been used in above formula as 1-Jan-2017 was Sunday. You can use any year where 1-Jan was Sunday like year 2023.
To show only 3 characters of the Weekday Name, replace dddd with ddd
=TEXT(DATE(2017,1,A1),"ddd")
You can add a number to A1 if you want to show some other Weekday Name
Say, if you want to show 1 = Monday, 2 = Tuesday… 7 = Sunday, just add 1 to A1
=TEXT(1+DATE(2017,1,A1),"dddd")
Say, if you want to show 1 = Friday, 2 = Saturday… 7 = Thursday, just add 5 to A1
=TEXT(5+DATE(2017,1,A1),"dddd")
16. Convert a Weekday Name to Number
Say Cell A1 contains the string Sunday, Monday….Saturday (or Sun, Mon… Sat) and you
want to show 1, 2 7, then following formula can be used to return the numbers. Sunday
will be 1 and Saturday will be 7.
=ROUND(SEARCH(LEFT(A1,2),"SuMoTuWeThFrSa")/2,0)
=MATCH(LEFT(A1,2),{"Su","Mo","Tu","We","Th","Fr","Sa"},0)
If we want to return some other number to weekdays, then formula can be tweaked accordingly. For example, to make Mon = 1 and Sun = 7
=ROUND(SEARCH(LEFT(A1,2),"MoTuWeThFrSaSu")/2,0)
=MATCH(LEFT(A1,2),{"Mo","Tu","We","Th","Fr","Sa","Su"},0)
17. Financial Year Formula (e.g. 2015-16 or FY16)
A good number of countries don't follow calendar year as the financial year. For example, India's financial year start is 1-Apr and finishes on 31-Mar. Hence, currently (20-Feb-16), the financial year is 2015-16 (It is also written as FY16). On 1-Apr-16, it will become 2016- 17 (It is also written as FY17).
Now if a date is given, then following formula can be used to derive 2015-16 kind of result.
=YEAR(A1)-(MONTH(A1)<=3)&"-"&YEAR(A1)+(MONTH(A1)>3)
To generate FY16 kind of result, following formula can be used
="FY"&RIGHT(YEAR(A1)+(MONTH(A1)>3),2)
18. Converting Date to a Calendar Quarter
Assuming date is in Cell A1. You want to convert it into a quarter (1, 2, 3 & 4). Jan to Mar is 1, Apr to Jun is 2, Jul to Sep is 3 and Oct to Dec is 4.
=CEILING(MONTH(A1)/3,1) OR
= ROUNDUP(MONTH(A1)/3,0) OR
=CHOOSE(MONTH(A1),1,1,1,2,2,2,3,3,3, 4,4,4)
19. Converting Date to a Indian Financial Year Quarter
Assuming date is in Cell A1. You want to convert it into a Indian Financial Year Quarter. Jan to Mar is 4, Apr to Jun is 1, Jul to Sep is 2 and Oct to Dec is 3.
=CEILING(MONTH(EDATE(A1,-3))/3,1) OR
= ROUNDUP(MONTH(EDATE(A1,-3))/3,0) OR
=CHOOSE(MONTH(A1),4,4,4,1,1,1,2,2,2,3,3,3)
20. Determine Quarter for Fiscal Year
Few countries follow different quarter other than Q1 from Jan-Mar and Q2 for Apr-Jun. In case of Jan-Mar as Q1, formula is simple (if cell A2 is date)
=ROUNDUP(MONTH(A2)/3,0)
This will give result as 1, 2, 3 & 4 for the quarters. If you want, you can concatenate "Q" in the formula to show Q1, Q2 etc as below
="Q"&ROUNDUP(MONTH(A2)/3,0)
If your financial / fiscal year starts in Apr, then for Jan-Mar, quarter is 4 whereas for Apr to Jun, quarter is 1 and so on. In this case, you can use following formula
=CEILING(MONTH(EDATE(A1,-3))/3,1)
= ROUNDUP(MONTH(EDATE(A1,-3))/3,0)
If your financial / fiscal year starts in Jul, then for Jan-Mar, quarter is 3 whereas for Jul to Sep, quarter is 1 and so on. In this case, you can use following formula
=CEILING(MONTH(EDATE(A1,-6))/3,1)
= ROUNDUP(MONTH(EDATE(A1,-6))/3,0)
If your financial / fiscal year starts in Oct, then for Jan-Mar, quarter is 2 whereas for Oct to Dec, quarter is 1 and so on. In this case, you can use following formula
=CEILING(MONTH(EDATE(A1,-9))/3,1)
= ROUNDUP(MONTH(EDATE(A1,-9))/3,0)
21. Calculate Age from Given Birthday
=DATEDIF(A1,TODAY(),"y")&" Years "&DATEDIF(A1,TODAY(),"ym")&" Months "&DATEDIF(A1,TODAY(),"md")&" Days"
22. Convert from dd/mm/yy to mm/dd/yy (DMY to MDY)
Say you have following dates in DMY format 24/8/22
24/8/2022
4/08/92
04/08/1992
And you need to convert them into MDY format, then use the following formula
Case1 – if your default date format is MDY
=FILTERXML("<t><s>"&SUBSTITUTE(TEXT(A1,"mm/dd/yyyy"),"/","</s><s>")&"</s></t
>","//s[2]")&"/"&FILTERXML("<t><s>"&SUBSTITUTE(TEXT(A1,"mm/dd/yyyy"),"/","</s
><s>")&"</s></t>","//s[1]")&"/"&FILTERXML("<t><s>"&SUBSTITUTE(TEXT(A1,"mm/d
d/yyyy"),"/","</s><s>")&"</s></t>","//s[3]")
Case2 – if your default date format is DMY
=FILTERXML("<t><s>"&SUBSTITUTE(TEXT(A1,"dd/mm/yyyy"),"/","</s><s>")&"</s></t
>","//s[2]")&"/"&FILTERXML("<t><s>"&SUBSTITUTE(TEXT(A1,"dd/mm/yyyy"),"/","</s
><s>")&"</s></t>","//s[1]")&"/"&FILTERXML("<t><s>"&SUBSTITUTE(TEXT(A1,"dd/m
m/yyyy"),"/","</s><s>")&"</s></t>","//s[3]")
23. Convert from mm/dd/yy to dd/mm/yy (MDY to DMY)
Say you have following dates in MDY format 8/24/22
8/24/2022
8/04/92
08/04/1992
And you need to convert them into DMY format, then use following formula
Case1 – if your default date format is MDY
=(FILTERXML("<t><s>"&SUBSTITUTE(TEXT(A1,"mm/dd/yyyy"),"/","</s><s>")&"</s></ t>","//s[2]")&"/"&FILTERXML("<t><s>"&SUBSTITUTE(TEXT(A1,"mm/dd/yyyy"),"/","</s
><s>")&"</s></t>","//s[1]")&"/"&FILTERXML("<t><s>"&SUBSTITUTE(TEXT(A1,"mm/d
d/yyyy"),"/","</s><s>")&"</s></t>","//s[3]"))
Case2 – if your default date format is DMY
=FILTERXML("<t><s>"&SUBSTITUTE(TEXT(A1,"dd/mm/yyyy"),"/","</s><s>")&"</s></t
>","//s[2]")&"/"&FILTERXML("<t><s>"&SUBSTITUTE(TEXT(A1,"dd/mm/yyyy"),"/","</s
><s>")&"</s></t>","//s[1]")&"/"&FILTERXML("<t><s>"&SUBSTITUTE(TEXT(A1,"dd/m
m/yyyy"),"/","</s><s>")&"</s></t>","//s[3]")
Note – Basically MDY to DMY and DMY to MDY are same formulas as we are just swapping the place of MM with DD and doing nothing else.
24. Number to Date Format Conversion
If you have numbers like 010216 and you want to convert this to date format, then the following formula can be used
=--TEXT(A1,"00\/00\/00") for 2 digits year
Note – Minimum 5 digits are needed for above formula to work
If you have numbers like 01022016 and you want to convert this to date format, then the following formula can be used
=--TEXT(A1,"00\/00\/0000") for 4 digits year
Note – Minimum 7 digits are needed for above formula to work
25. Number to Time Format Conversion
If you have numbers like 1215 and you want to convert this to hh:mm format, then the following formula can be used
=--TEXT(A1,"00\:00")
Note – Minimum 3 digits are needed for above formula to work To convert to hh:mm:ss format
=--TEXT(A1,"00\:00\:00")
Note – Minimum 5 digits are needed for above formula to work
26. Convert Time to Decimal Hours, Minutes and Seconds
Say A1 has the time 11:35 PM, then you can use following formulas To convert into Decimal hours
=A1*24
To convert into Decimal minutes
=A1*1440
(1440 is nothing but 24*60)
To convert into Decimal seconds
=A1*86400
(86400 is nothing but 24*60*60)
(Note – You will need to format your result cell in decimal format)
27. Convert Decimal Hours, Minutes and Seconds to Time
Say A1 has decimal hours 23.58, then you can use following formula to convert it back into time
=A1/24
If it has decimal minutes say 1415, then you can use following formula to convert it back into time
=A1/1440
If it has decimal seconds say 84900, then you can use following formula to convert it back into time
=A1/86400
(Note – You will need to format your result cell in Time format)
28. Generate a Sequence of Dates
Generate 90 sequential dates starting 1-Apr-21. Let's say that the date is in cell A1. You can use either of following formulas
=SEQUENCE(90,,A1)
=ROW(INDIRECT(A1&":"&A1+89))
Now, let's generate all dates of a given month. Let's say this is Feb-2021. You can use following formula where A1 has the date 1-Feb-2021
=SEQUENCE(DAY(EOMONTH(A1,0)),,A1)
=ROW(INDIRECT(A1&":"&EOMONTH(A1,0)))
Above formulas will generate dates in a column. To generate in a row
=SEQUENCE(,90,A1)
=TRANSPOSE(ROW(INDIRECT(A1&":"&A1+89)))
=SEQUENCE(,DAY(EOMONTH(A1,0)),A1)
=TRANSPOSE(ROW(INDIRECT(A1&":"&EOMONTH(A1,0))))
29. Generate a Sequence of Times
Generate 40 sequential times starting at 11 AM with an increment of 15 minutes where A1:=11:00 AM
=A1+SEQUENCE(40,,,15/(24*60))
=A1+(ROW(1:40)-1)*15/(24*60)
30. How to Know if a Year is a Leap Year
Let's say that A1 contains the year. To know whether it is a Leap Year or not, use following formula -
=MONTH(DATE(A1,2,29))=2
=DAY(EOMONTH(DATE(A1,2,1),0))=29
TRUE means that it is Leap Year and FALSE means that this is not a Leap Year.
31. Last Working Day of the Month If a Date is Given
If A1 holds a date, the formula for calculating last Working Day of the month would be
=WORKDAY(EOMONTH(A1,0)+1,-1)
The above formula assumes that your weekends are Saturday and Sunday.
But, if your weekends are different (e.g. in gulf countries), you can use following formula -
=WORKDAY.INTL(EOMONTH(A1,0)+1,-1,"0000110")
Where 0000110 is a 7 character string, 1 represents a weekend and 0 is a working day. First digit is Monday and last digit is Sunday. The above example is for Gulf countries where Friday and Saturday are weekends.
You also have an option to give a range which has holidays. In that case, your formula would become
=WORKDAY(EOMONTH(A1,0)+1,-1,D1:D10)
=WORKDAY.INTL(EOMONTH(A1,0)+1,-1,"0000110",D1:D10)
Where range D1:D10 contains the list of holidays.
32. First Working Day of the Month if a Date is Given
If A1 contains a date, then formula for First Working Day of the month would be
=WORKDAY(EOMONTH(A1,-1),1)
The above formula assumes that your weekends are Saturday and Sunday.
But, if your weekends are different (e.g. in gulf countries), you can use following formula -
=WORKDAY.INTL(EOMONTH(A1,-1),1,"0000110")
Where 0000110 is a 7 character string, 1 represents a weekend and 0 is a working day. First digit is Monday and last digit is Sunday. The above example is for Gulf countries where Friday and Saturday are weekends.
You also have option to give a range which has holidays. In that case, your formula would become
=WORKDAY(EOMONTH(A1,-1),1,D1:D10)
=WORKDAY.INTL(EOMONTH(A1,-1),1,"0000110",D1:D10)
Where range D1:D10 contains the list of holidays.
33. Determine Number of Working Days in a Year
Suppose, you have been given a year in A1 (Say A1 = 2021) and you need to determine the number of working days in a Year, then your formula to determine number of working days would be –
=NETWORKDAYS(DATE(A1,1,1),DATE(A1,12,31))
The above formula is based on the fact that Saturdays and Sundays are weekends. Starting Excel 2010, you can control the weekends in the formula and function is NETWORKDAYS.INTL
=NETWORKDAYS.INTL(DATE(A1,1,1),DATE(A1,12,31),"0000110")
In the string "000110" – First digit is Monday and last digit is Sunday. 1 defines that particular day as weekend.
If you have got your list of holidays in a range say B1:B20 (B1:B20 should contain dates in date format), you can have following formulas
=NETWORKDAYS(DATE(A1,1,1),DATE(A1,12,31),B1:B20)
=NETWORKDAYS.INTL(DATE(A1,1,1),DATE(A1,12,31),"0000110",B1:B20)
34. Determine Number of Working Days in a Month
Let's say you need to find number of working days in year 2022 for the month of Jul where year is in A1 and month in number format is in A2 (Hence A2 should be 7 not Jul), then you can use following formula
=NETWORKDAYS(DATE(A1,A2,1),EOMONTH(DATE(A1,A2,1),0))
The above formula is based on the fact that Saturdays and Sundays are weekends. Starting Excel 2010, you can control the weekends in the formula and function is NETWORKDAYS.INTL
=NETWORKDAYS.INTL(DATE(A1,A2,1), EOMONTH(DATE(A1,A2,1),0),"0000110")
In the string "000110" – First digit is Monday and last digit is Sunday. 1 defines that particular day as weekend.
If you have got your list of holidays in a range say B1:B20 (B1:B20 should contain dates in date format), you can have following formulas
=NETWORKDAYS(DATE(A1,A2,1), EOMONTH(DATE(A1,A2,1),0),B1:B20)
=NETWORKDAYS.INTL(DATE(A1,A2,1), EOMONTH(DATE(A1,A2,1),0),"0000110",B1:B20)
35. How Many Mondays or any other Day of the Week between 2 Dates
Suppose A1 = 23-Jan-16 and A2 = 10-Nov-16. To find number of Mondays between these two dates
=SUM(--(WEEKDAY(ROW(INDIRECT(A1&":"&A2)))=2))
=SUMPRODUCT(--(TEXT(ROW(INDIRECT(A1&":"&A2)),"ddd")="Mon"))
=SUMPRODUCT(--(WEEKDAY(ROW(INDIRECT(A1&":"&A2)))=2))
=SUMPRODUCT(--(TEXT(ROW(INDIRECT(A1&":"&A2)),"ddd")="Mon"))
“Mon" can be replaced with any other day of the week as per need.
36. Find Number of Friday the 13th between Two Given Dates
Assume you have been given two dates A1:=1-Jan-2014
A2:=25-Nov-2016
You can calculate number of Friday the 13th between these two dates by following formula
=SUMPRODUCT((WEEKDAY(SEQUENCE(A2-A1+1,,A1))=6)*(DAY(SEQUENCE(A2- A1+1,,A1))=13))
=SUMPRODUCT((WEEKDAY(ROW(INDIRECT(A1&":"&A2)))=6)*(DAY(ROW(INDIRECT(A 1&":"&A2)))=13))
37. Calculate Next Working day if date falls on a Weekend
/ Holiday
Suppose you are given a date and you are asked to calculate next working day if date is of weekend. If date is a regular workday, then you should show the same date. For example – 8-Mar-19 is a working day. Hence, you should show the same date. But if this is either 9- Mar-19 or 10-Mar-19 which are Saturday and Sunday, then you must show 11-Mar-19 as the next workday. In this case, formula to be used would be
=WORKDAY(A2-1,1)
Assuming, your holidays are in E2:E3, then formula would be
=WORKDAY(A2-1,1,$E$2:$E$3)
Note – If you are using weekends other than Saturday and Sunday, use WORKDAY.INTL with appropriate parameters.
38. Calculate Previous Working day if date falls on a Weekend / Holiday
Suppose you are given a date and you are asked to calculate Previous Working day if date is of weekend. If date is a regular workday, then you should show the same date.
For example – 8-Mar-19 is a working day. Hence, you should show the same date. But if this is either 9-Mar-19 or 10-Mar-19 which are Saturday and Sunday, then you must show 8- Mar-19 as the previous workday.
In this case, formula to be used would be
=WORKDAY(A2+1,-1)
Assuming, your holidays are in E2:E3, then formula would be
=WORKDAY(A2+1,-1,$E$2:$E$3)
Note – If you are using weekends other than Saturday and Sunday, use WORKDAY.INTL with appropriate parameters.
39. Date for Nth Day of the Year
Suppose A1 contains the Year and you are asked to find 69th day of the year which is contained in A2. Then formula for finding Nth day of the year would be
=DATE(A1,1,1)+A2-1
40. Extract Date and Time from Date Timestamp
Suppose you have a date timestamp value in cell A1 A1 = 06/14/15 10:15 PM
And you want to extract date and time out of this.
To extract date, use following formula and format the result cell as date
= INT(A1)
To extract time, use following formula and format the result cell as time
= MOD(A1,1)
41. First Working Day of the Year
If a year is given in A1 say 2016, below formula can be used to know the first working day of the year (format the result as date)
=WORKDAY(DATE(A1-1,12,31),1)
=WORKDAY(DATE(A1,1,1)-1,1)
The above formula assumes that your weekends are Saturday and Sunday.
But, if your weekends are different (e.g. in gulf countries), you can use following formula -
=WORKDAY.INTL(DATE(A1-1,12,31),1,"0000110")
Where 0000110 is a 7 character string, 1 represents a weekend and 0 is a working day. First digit is Monday and last digit is Sunday. The above example is for Gulf countries where Friday and Saturday are weekends.
You also have option to give a range which has holidays. In that case, your formula would become
=WORKDAY(DATE(A1-1,12,31),1,D1:D10)
=WORKDAY.INTL(DATE(A1-1,12,31),1,"0000110",D1:D10)
Where range D1:D10 contains the list of holidays.
42. Last Working Day of the Year
If a year is given in A1 say 2016, below formula can be used to know the last working day of the year (format the result as date)
=WORKDAY(DATE(A1+1,1,1),-1)
=WORKDAY(DATE(A1,12,31)+1,-1)
The above formula assumes that your weekends are Saturday and Sunday.
But, if your weekends are different (e.g. in gulf countries), you can use following formula -
=WORKDAY.INTL(DATE(A1+1,1,1),-1,"0000110")
Where 0000110 is a 7 character string, 1 represents a weekend and 0 is a working day. First digit is Monday and last digit is Sunday. The above example is for Gulf countries where Friday and Saturday are weekends.
You also have option to give a range which has holidays. In that case, your formula would become
=WORKDAY(DATE(A1+1,1,1),-1,D1:D10)
=WORKDAY.INTL(DATE(A1+1,1,1),-1,"0000110",D1:D10)
Where range D1:D10 contains the list of holidays.
43. Convert from Excel Date (Gregorian Date) to Julian Date
Q. First what is a Julian Date?
A. A Julian date has either 7 digits or 5 digits date and these are generally used in old IT legacy systems.
7 Digits - YYYYDDD - 2016092 (This is 1-Apr-2016. 92 means that this is 92nd day from 1- Jan in that year)
5 Digits - YYDDD - 16092
Q. What formulas to use to convert Excel Dates to Julian Dates where A1 has the date say 14-Feb-2022?
A. For 7 Digits, use following formula
=--TEXT(A1,"yyyy")&TEXT(A1-DATE(YEAR(A1),1,1)+1,"000")
For 5 Digits, use following formula
=--TEXT(A1,"yy")&TEXT(A1-DATE(YEAR(A1),1,1)+1,"000")
44. Convert from Julian Dates to Excel (Gregorian) Dates
For 7 Digits Julian Dates, following formula should be used
=DATE(LEFT(A1,4),1,RIGHT(A1,3))
For 5 Digits Julian Dates, following formula should be used
=DATE(YEAR("1-1-"&LEFT(A1,2)),1,RIGHT(A1,3))
45. Convert a Number into Years and Months
Suppose, you have been given a number into cell A1 say 26 and you want to display it as 2 Years and 4 Months, you can use following formula -
=INT(A1/12)&" Years and "&MOD(A1,12)&" Months"
Now, an user can become more demanding and he can say that if month is less than 12, then Years should not be displayed. For example, he might say that 8 should be converted to 8 Months and it should not be shown as 0 Years and 8 Months.
In this case, the formula would be -
=IF(INT(A1/12)>0,INT(A1/12)&" Years and ","")&MOD(A1,12)&" Months"
Now 8 will be displayed as 8 Months only not as 0 Years and 8 Months.
Now, user can ask more. He can say when I give 12, it displays as 1 Years and 0 Months and he simply wants to see 1 Years only. And for 36, he wants to see only 3 Years not 3 Years 0 Months. In this case, formula will have to be tweaked more. Now, the formula becomes -
=IF(INT(A1/12)>0,INT(A1/12)&" Years ","")&IF(MOD(A1,12)=0,"",MOD(A1,12)&"
Months")
Now an user can come and can ask for one last thing. He can say that if this is 1 Year or 1 Month, it should not be displayed as Years or Months as 1 is not plural. Hence, 25 should be displayed as 2 Years and 1 Month not as 2 Years and 1 Months. Hence, 18 should not be displayed as 1 Years and 6 Months but as 1 Year and 6 Months. Similarly 13 should be displayed as 1 Year and 1 Month not as 1 Years and 1 Months.
=IF(INT(A1/12)>0,INT(A1/12)&" Year"&IF(INT(A1/12)>1,"s","")&" and
","")&MOD(A1,12)&" Month"&IF(MOD(A1,12)>1,"s","")
46. Find the Next Week of the Day
There are 2 scenarios in this case. For example, if today’s date is 2-Jan-17 (Monday) and I try to find the next Monday, I can get either 2-Jan-17 or 9-Jan-17 as per need. For Tuesday to Sunday, it is not a problem as they come after 2-Jan-17 only.
47. Find the Previous Week of the Day
48. Count Cells Starting (or Ending) with a particular String
49. Count No. of Cells Having Numbers Only
50. Reverse a String
Comments
Post a Comment