Friday, May 23, 2014

Thursday, May 15, 2014

Conditional Formatting Tips and Tricks

Finding the Unique Values with the help of Conditional Formatting.


Highlight mistakes, errors, omissions and repetitions

Entering large amounts of data into a spreadsheet is monotonous and pron to mistakes, omissions and repetitions. This can be avoided by using conditional formatting whenever typing or pasting a formula over a large range of cells.

To highlight a cell containing an error or omission:

Select “Conditional Formating”, “New Rule”, and “Format only cells that contain”
In the drop-down list under “Format only cells with:” select either “Error” or “Blanks” depending on what you want highlighted
Format your cells to your desired style

To highlight cells containing duplicate values:

Select “Conditional Formating”, “New Rule”, and “Format only unique or duplicate values”
Format your cells to your desired colors

Highlighting alternate rows or columns

Data presented in a large table is difficult to read because your eyes may have trouble following the rows and columns, especially when scrolling. To remedy this, try highlighting or changing the background color of alternative rows or columns. You could do this manually, but if you have a large table that keeps changing, you need to use Conditional Formatting.

Select the data section of your table you want to format
Click “Conditional formatting” in the “Home” ribbon
Click “New rule” near the bottom of the drop-down menu
Select “Use a formula to determine which cells to edit”
To highlight alternate rows, enter the formula =MOD(ROW(),2)=0 in the input box under “Format values where this formula is true:”
  This means whenever row() of the current cell is even, your desired formatting will be applied
  •   To apply formatting to odd rows, just input =MOD(ROW(),2)=1 as the formula
  •   To highlight alternate columns instead of rows, use =MOD(COLUMN(),2)=1 formula
  •   What if you want to change background color of every 3rd row: use =MOD(ROW(),3)=0 instead

Format background colors, text, text color, borders, etc to your desired style. When you are done, the dialog should look something like the sample to the right:  Click OK.

Add “In-Cell” graphs

In-cell graphing is a handy trick that basically uses REPT() function, which repeats a character a given number of times, to generate bar-charts with in a cell. You can apply conditional formatting to the characters to give the charts good effect. Here is a sample:

 The graph highlights the cells that are greater than the average number of sales for the month by changing the font color to red and making it bold.

To create the graph:

Enter the formula =REPT(“I”,C4/100) in C4 of the “Graph” column then copy the formula to the cells beneath. (You will need to adjust the “divided by 100″ depending on the size of the number in the “Amount” column)

To create the conditional formating:

Click “Conditional Formating”, “New Rules” and “Use a formula to determine which cells to format”
Under “Format values where this formula is true:” enter

=($C4>AVERAGE($C$4:$C$33))

Click “Format” and change font color to “Red” and font style to “Bold” (or whatever format you want).
Click “Okay”

Creating a quick project plan / gantt chart using conditional formatting.


Project plans / gantt charts are everyday activity in most of our lives. Creating a simple and snazzy project plan template in excel is not a difficult job, using conditional formatting a bit of formulas you can do it no time.

First create a table structure like shown above, with columns like Activity, start and end day, day 1, 2,3, etc…
Now, whenever a day falls between start and end day for a corresponding activity, we need to highlight that row. For that we need to identify whether a day falls between start and end. We can do that with the below formulas,
    =IF(AND(F$8>=$D9, F$8<=$E9),"1","")
Which means, whenever, the day number represented on the top row is between start and end we will in 1 in the corresponding cell.
Next, whenever the cell value is 1, we will just fill the cell with a favorite color and change the font to same color, so that we dont see anything but a highlighted cell, better still, whenever you change the start or end dates, the color will change automatically. This will be done by conditional formatting like below:


Highlight the Non-Multiples
Shown below is the sample data for this conditional formatting example.


To add the conditional formatting, and highlight the non-multiples in column D:
Select cells D2:D6, with D2 as the active cell
On the Excel Ribbon's Home tab, click Conditional Formatting, and click New Rule
In the New Formatting Rule dialog box, under 'Select a Rule Type', click 'Use a formula to determine which cells to format'
In the formula box, type the MOD formula:   =MOD(D2,C2) <> 0
Click Format, and on the Fill tab, select Red, then click OK, twice, to close the dialog boxes.
The MOD function returns the remainder after a number is divided by divisor. If the result is zero, then D2 is a multiple of C2.
Now the non-multiples in column D highlighted in red.


Format the Highest Value

To set up the conditional formatting for the highest value:
Select cells C2:E6, with C2 as the active cell
On the Excel Ribbon's Home tab, click Conditional Formatting, and click New Rule
In the New Formatting Rule dialog box, under 'Select a Rule Type', click 'Use a formula to determine which cells to format'
In the formula box, type the MAX formula:   =C2 = MAX($C2:$E2) The first reference to C2 is relative, so each cell will check its value compared to the MAX in the $C2:$E2 range.
Click Format, and on the Font tab, select Red as the font colour, then click OK, twice, to close the dialog boxes.



Now the highest values are highlighted in each row.



Format the Second Highest Value
To set up the conditional formatting for the second highest value:
Select cells C2:E6, with C2 as the active cell
On the Excel Ribbon's Home tab, click Conditional Formatting, and click New Rule
In the New Formatting Rule dialog box, under 'Select a Rule Type', click 'Use a formula to determine which cells to format'
In the formula box, type the LARGE formula:   =C2 = LARGE($C2:$E2,2)
Click Format, and on the Font tab, select Blue as the font colour, then click OK, twice, to close the dialog boxes.
Format the Lowest Value
To set up the conditional formatting for the second highest value:
Select cells C2:E6, with C2 as the active cell
On the Excel Ribbon's Home tab, click Conditional Formatting, and click New Rule
In the New Formatting Rule dialog box, under 'Select a Rule Type', click 'Use a formula to determine which cells to format'
In the formula box, type the MIN formula:   =C2 = MIN($C2:$E2)
Click Format, and on the Font tab, select Green as the font colour, then click OK, twice, to close the dialog boxes.
Now the highest value in each row is highlighted in red, the second highest is blue, and the lowest is green.


Validation Rule for Conditional Formatting :

Conditional formatting won't let you refer to cells on a different worksheet, or in a different workbook. However, you can refer to a workbook level named range that's on a different worksheet.



Wednesday, May 14, 2014

Excel Tips and Tricks : Date & Time

Calculate the Difference between two set of time.


A very much needed Trick to compute the difference between two set of timing:

The magic formula to use is =MOD([Departure]-[Arrival],1)



How to Calculate Over time and wages.



Create a basic time sheet as described above, add lunch breaks , if required,

Step 1: Data Entry

In Cell J1 : type employee's hourly rate
In cell J2: type employee's overtime rate.
Change the Total Hours column to read: Regular Hours (Column F)
Add a new column called: Overtime Hours (Column G)
To simplify, you might want to remove the "Total Pay" Column
Format Columns F & G to "Number" with 2 Decimal places

Step 2: Calculate Hours worked
In Cell F2, type:     =IF((((C2-B2)+(E2-D2))*24)>8,8,((C2-B2)+(E2-D2))*24)
In cell G2, type        =IF(((C2-B2)+(E2-D2))*24>8, ((C2-B2)+(E2-D2))*24-8,0)

Step 3: Drag down and total
In cell F10, sum regular hours, =SUM(F2:F8)
In cell G10, sum overtime hours =SUM(G2:G8)

Step 4: Calculate Pay:

In cell F11, type: =SUM(F10*$J$1)
In cell F12, type =SUM(G10*$J$2)
Sum F11 and F12 for total pay.  Type  =SUM(F11+G11)

CONVERT HOURS AND MINUTES INTO MINUTES

Convert Hours to Minutes in Excel. Here is how:

EXCEL 97-2003
Type your hours and minutes in an hh:mm format 
Click on "Format Cells"
On the Number Tab, under "custom", type [m] 

EXCEL 2007/2010/2013

Type your hours and minutes in an hh:mm format 
In the Excel Ribbon, Click on the Arrow Down near "Custom"
Click on "More Number Formats"
On the Number Tab, under "custom", type [m] 
Example:
Type 5:20
Change format to Custom and type [m] to see 320.

Question: How do I convert conventional hours into a decimal number?

Short Answer:
To convert hours using a calculator: 
Divide the minutes by 60. 
  
To convert hours using Excel: 
Change the cell format to "Number" with 2 decimal places and multiply it by 24

Example: My worker worked for 4hr 23 min at a rate of 13.50. How much do I pay him?
Step 1:       Divide:         23 / 60 = 0.38 
Step 2:       Add:             4 + 0.38 = 4.38
To pay your worker, multiply 4.38 by 13.50

USING EXCEL: 

If you like to use excel:
Step 1            In cell A1,                 Enter the time as hh:mm 
Step 2            In Cell B1, type         =(A1)*24 
Step 3            Change the format of Cell B to "Number" with 2 decimal places.
Example:
Step 1        In cell A1        Type 4:23  
Step 2        In cell B1       Type =(A1)*24 
Step 3        Change the format of cell B to "Number" with 2 decimal places.  You will now see 4.38
To pay your worker,  enter in cell C1 =(b1*13.50)

Make Time Count by using Formula


Imagine that you are using Excel to help you fill out a timecard by adding up the hours you work each day. To add the hours for Monday, you would type this formula in cell B4:
=(B3-B2)*24

As you type, the equal sign (=) tells Excel that this is a formula. B3 and B2 are thecell references that refer to the values in those cells. The minus sign operator tells Excel to subtract one value from the other.
Operations within parentheses are calculated first, so Excel subtracts first. Then the asterisk operator tells 
Excel to multiply the result of B3-B2 by 24, to convert that result from Excel's decimal time system to a 24-hour system. The result of the formula is 9 hours.

Computing Age

Computing someone's age from their birthday is simple, using the =DATEDIF function.  Suppose that a person's birthday is in A1. The following will return their age in Years, Month, and Days:

=DATEDIF(A1,NOW(),"y")&" Y, "& DATEDIF(A1,NOW(),"ym")& 
" M, " & DATEDIF(A1,NOW(),"md") & " D".

Creating A Series Of Workdays

If you want to create a series of dates in a column, consisting of only weekdays (Monday through Fridays), enter your starting date in a cell (A4, in the example), and then enter the following formula in the cell below that cell.

=IF(WEEKDAY(A4)=7,A4+2,IF(WEEKDAY(A4)=6,A4+3,A4+1))

Then use Fill Down to fill out your entire series of dates.

Next Day Of Week After A Date

To return the date of the next day of week following a given date, use the formula

=A1+(WEEKDAY(A1)>=C1)*7-WEEKDAY(A1)+C1

Where A1 is a date and C1 is the day-of-week number (1 = Sunday, 2 = Monday, ..., 7 = Saturday).  For example, if A1 contains the date 15-Jan-2002 (a Tuesday) and C1 contains the number 6 (indicating Friday), the formula will return 18-Jan-2002, a Friday.  

Note that if the day of week in C1 is same day of week as the date in A1, the formula returns a date 1 week later than A1.  For example, if A1 is 15-Jan-2002 (Tuesday) and C1 contains 3 (indicating Tuesday), the formula returns the date 22-Jan-2002, a Tuesday.  

If you want the formula to return the same date, use the formula

=A1+(WEEKDAY(A1)>C1)*7-WEEKDAY(A1)+C1.

Days In Month

To return the number of days in a month, use the following formula.  Suppose cell A1 contains the date 15-Jan-1998.

=DAY(DATE(YEAR(A1),MONTH(A1)+1,0))

This will return 31, the number of days in January, 1998.

First Day Of Month

You can use the following formula to get the date of the first day of the month.   Suppose the 
date in cell A1 is 15-Jan-1998.

=DATE(YEAR(A1),MONTH(A1),1)

This will return 1-Jan-1998.
Last Day Of Month

You can use the following formula to get the date of the last day of the month.   Suppose the 
date in cell A1 is 15-Jan-1998.

=DATE(YEAR(A1),MONTH(A1)+1,0)

This will return 31-Jan-1998.

First Weekday Day Of Month

You can use the following formula to get the date of the last weekday (Monday thru Friday) of the month.   Suppose the date in cell A1 is 1-June-2002.

=DATE(YEAR(A1),MONTH(A1),1)+CHOOSE(WEEKDAY(DATE(YEAR(A1),MONTH(A1),1)),1,0,0,0,0,0,2)

This will return 3-June-2002.

Last Weekday Day Of Month

You can use the following formula to get the date of the last weekday (Monday thru Friday) of the month.   Suppose the date in cell A1 is 6-Nov-2002.

=DATE(YEAR(A1),MONTH(A1)+1,0)-(MAX(0,WEEKDAY(DATE(YEAR(A1),MONTH(A1)+1,0),2)-5))

This will return 29-Nov-2002.  Another formula, given a month and year, is the following array formula:

=MAX(ROW(INDIRECT(DATE(year,month,1)&":"&DATE(year,month+1,0)))*(WEEKDAY(ROW(INDIRECT(DATE(year,month,1)&":"&DATE(year,month+1,0))),2)<6))

Last Day Of Previous Month

You can use the following formula to get the date of the last day of the previous month.  Suppose the date in cell A1 is 15-Jan-1998.

=DATE(YEAR(A1),MONTH(A1),0)

This will return 31-December-1997.

Nth Day Of Week For A Month And Year

This formula will return will return the date of Nth day-of-week for a given month and year. For example, it will return 26-March-98 for the 4th Thursday of March, 1998.   Days-of-week range from 1 to 7, with Sunday = 1 and Saturday = 7.

=DATE(Yr,Mon,1+((Nth-(DoW>=WEEKDAY(DATE(Yr,Mon,1))))*7)+
(DoW-WEEKDAY(DATE(Yr,Mon,1))))

Where Yr, Mon, Nth,  and DoW are cell references or values indicating Year, Month, Nth, and Day-Of-Week.

Nth Day Of Week For A Year

This formula will return will return the date of Nth day-of-week for a given  year. For example, it will return 11-April-2001 for the 15th Wednesday of the year 2001.   Days-of-week range from 1 to 7, with Sunday = 1 and Saturday = 7.

=DATE(Yr,1,1+(Nth-(Dow>=WEEKDAY(DATE(Yr,1,1))))*7)+
Dow-WEEKDAY(DATE(Yr,1,1))

Where Yr,Nth, and DoW are cell references or values indicating Year, Month, Nth, and Day-Of-Week.

Number Of Mondays In Period

If you need to return the number of Monday's (or any other day) that occur within an interval between two dates, use the following Array Formula: 

=SUM(IF(WEEKDAY(A2-1+ROW(INDIRECT("1:"&TRUNC(B2-A2)+1)))=C2,1,0))

This formula assumes the following: 
A2 contains the beginning date of the interval
B2 contains the ending date of the interval
C2 contains the day-of-week number (1=Sunday, 2=Monday,...,7=Saturday)

Week Differences

You cannot use the =DATEDIF function of return the difference of of two dates in weeks, so you can use the following function return the number of weeks and days between two dates:

=TRUNC((B1-A1)/7)&" Weeks "&MOD(B1-A1,7)&" Days"

What Day Is It?

If you need to know the day-of-week for a specific date, the =WEEKDAY function gives you a number between 1 and 7 indicating the day, (1=Sunday, 2=Monday, ... , 7=Saturday).   To convert this number to the actual name of the day ("Sunday", for example), use the =TEXT function: 

=TEXT(A1, "ddd") returns the three character abbreviation for the day, e.g., "Mon". 
=TEXT(A1,"dddd") returns the full name of the day, e.g., "Monday".

To determine if a date is a work day (Monday - Friday), create a name called WorkDays which refers to 
={2;3;4;5;6}

Then following function will return TRUE or FALSE, indicating whether the date in A1 is a work day:
=IF(ISERROR(VLOOKUP(WEEKDAY(A1),WorkDays,1,0)),FALSE,TRUE)

What Quarter Is It?

To return the quarter of the year, use the formula 

=ROUNDUP(MONTH(A1)/3,0) .

What Week Is It?

If you need to know what week of the year at date falls in, use the following formula:

=TRUNC(((A1-DATE(YEAR(A1),1,1))/7))+1+
IF(WEEKDAY(DATE(YEAR(A1),1,1))>WEEKDAY(A1),1,0)

This will return a number between 1 and 53, indicating the week of the year for the date in A1.

How can I calculate the date that a project ends, this date falls after a certain amount of years, months and days?