Tuesday, November 18, 2014

How to create Cell charts in excel ?

Ever wondered how the small graphs are shown in the cells in excel. These are used to show small trends for many different values, which can be easily understood with these views. e.g. in case of stock company values these charts can be use to show the market trends.


There is a new feature introduced in the Microsoft Excel 2010 which helps you to insert the graphs in cells. This new feature is the sparklines for a single cell. Using these sparklines you can now create tiny integrated graphics within each cell. These sparklines can be easily used to detect patterns of the data tables. This is a very simple and quick feature, to highlight important trends in the that data (such as seasonal increases and decreases).

Below are the guidelines to create the spraklines charts in cell :

1. To make use of sparklines, select the cell where we need to place the tiny graph.

2. Then, click on the Insert tab àsparklines. here you have 3 types of charts to choose Line , column and gain or loss.

3. Once you choose the type, you will get a pop-up message to choose the Target cell and the Data Range.

4. Update the data range, where your data is present update the cell number in Location Range, where you need to see your graph.

5. Once the range is updated and you click ok, the graphs are generated instantly in the location range.


The choice of the sparkline chart type seems more visual in the online format. The format with gain or loss is very suitable for interpreting balance sheets.

It is very fast, simple and intuitive interpretation of the data table, identify trends and monitor developments. The graphs which were initially quite difficult to read as a set of numbers has now become easily understandable.

Wednesday, October 22, 2014

How to use VLOOKUP and HLOOKUP ?

VlookUp stands for vertical column look up. This formula is used to find the value in the column vertically.

e.g.


We have a table of employee details, where employee id, first name, last name, email id and contact number data is there. The data is in column A, B, C, D and E respectively.


This table contains data for 10000 employees.


Problem : We need to get the email id and contact number data for 43 employees in the output. 

The only input we have is employee id in column H.










Solution - Vlookup


below is the formula which can be used to get the employee details -


Get email id

=VLOOKUP(H2,A:E,4,0)

how it works ?

1. here H2 is the reference employee id for which we need to find the data
2. A:E is the table range where our data is present
3. 4 is the number of the column starting from column A, in which our data is present
4. 0 is for exact match

Similarly use the below formula to  get contact number

=VLOOKUP(H2,A:E,5,0)

Note - 

1. The reference value which we are using to look up the data should be always in the left hand side of the required output data. in above example employee id is on the left side of the data.
2. The data range should start from the reference number column. In above example range is starting from (A;E) where A is employee id column.
3. The number for the output column should be counted from the start column of reference value. In example above we are counting the output value from column A, i.e. our output values are in column 4 and 5.



 
HlookUp stands for horizontal row look up. This formula is used to find the value in the rows horizontally.

e.g.


We have a table of students marks details, where column headers are 

Student Name
English
Maths
Science
History.

The data is in column A, B, C, D and E respectively.


Data under Student Name column is -

Amol

Vijay

Kiran

Vidya

....
...
..
. and more

This table contains data for 5000 Students.

Problem : We need to find the marks of English and Science, only for Vijay and Vidya or for list of say, 30 students only.

The input we have is the table data in which we can use the user name and the subject name to lookup the required value.


example table:



Solution : Hlookup

below is the formula which can be used to get the required output
=HLOOKUP(B8,$A$1:$E$5,3,0)

result = 32

Below is the screenshot of output table, this table is on cells A8:C10.


how it works ?

1. here B8 is the subject name (English) for which we need to find the data
2. $A$1:$E$5 is the table range where our input data is present
3. 3 is the number of the row starting from column header, in which our data is present
4. 0 is for exact match


Similarly use the below formula to  get data for subject Science
=HLOOKUP(C8,$A$1:$E$5,3,0)

result = 27


There is one challenge in the above formula for which we need to take help of one more formula combining with Hlookup.



Challenge : For 5000 students how to enter the number automatically in step 3 above

Solution : use the MATCH formula to find the row number in which our required data is present

e.g. find row number for Vijay, use the below match formula

=MATCH(A9,$A$1:$A$5)


result = 3



how it works ?

1. here A9 is the Student name (Vijay) for which we need to find the data
2. $A$1:$A$5 is the table range where our input data is present


Now combining the Match formula with Hlookup, we can get the required output without manual entry.

Our actual Hlookup formula:
=HLOOKUP(B8,$A$1:$E$5,3,0)

Formula combined with MATCH:

=HLOOKUP(B8,$A$1:$E$5,MATCH(A9,$A$1:$A$5),0)

result = 32



How to calculate days in a month using Excel formula ?


Below is the formula which can be used to calculate the days in a specific month.


Enter any date in cell B2


Copy paste the below formula in Cell B3


=DAY(DATE(YEAR(B2),MONTH(B2)+1,1)-1)



e.g. if the value in the Cell B2 is 10/22/2014 (i.e. 22nd october 2014)


Then the result in the cell B3 will be 31



How it works ?


we will break up the above formula in  parts.


1. Year(B2)          - this will provide us the year of the date result (2014) 

2. Month(2) + 1   - this will provide us the next months number result (11)
3. 1                     - one is entered to get 1st date of next month 
4. -1                     - this minus one will give us last day of previous month result (10/31/2014)
5. Day                 - this formula will provide us the required day output result (31)

conclusion - Initially we are finding first day of next month, then subtracting it with 1 to get last day of current month and at the end with the help of day formula we get the last day i.e. 31 as output.


Done...

Monday, June 30, 2014

How to use the CASE and the INPUTBOX in Excel VBA ?

Below is the example of the input box and the Case, used in excel VBA to check, the letter belongs to which grade description.

Copy paste the below code to any of the Excel VBA module and run it. you will get the pop-up window to enter the input letter. Enter the letter and click OK.


You will get the message box with the letter is for description value.


Sub testcase()


Dim grade As String

grade = "A"
grade = InputBox("Enter the Grade from A to D")
Select Case grade

Case "A"

MsgBox grade & " is for High Distinction"

Case "B"

MsgBox grade & " is for Credit"

Case "C"

MsgBox grade & " is for Pass"

Case Else

MsgBox grade & " is for Fail"

End Select

End Sub

Using the code examples in the above macro, this can be modified to do different tasks at different situations.

e.g., if you want to write the grade against the marks in excel, we can modify the above code adding the loop code and mapping the grades to marks.

Done...

Thursday, May 15, 2014

How to find character in text using excel formula ?

You can use below formula to find the character in any word.

e.g. cell B1 contains the text Marks with 50% and we need to find if it contains %, we can write the below formula - 

=MID(B1,FIND("%",B1,1),1)

Output of the above formula will be %.



You can further customize this formula to write Found -

=IF(MID(B1,FIND("%",B1,1),1)="%","Found")

Output of the above formula will be Found.



If there is no "%" in cell B1 the formula will return #value! error, to overcome this we can customize the formula as below -

=IFERROR(IF(MID(B1,FIND("%",B1,1),1)="%","Found"),"Not Found")

If the character is missing in cell B1 then the output of the above formula will be Not Found.



You can replace the % to any character you need to find and you will get the output accordingly.


Done....

Tuesday, May 6, 2014

Find the difference between the two dates in excel

Below is the inbuilt function in excel which will retrieve the difference between two dates. We can get the results in number of days, number of months or number of years.

We can take a simple example to find the age difference from date of birth till today -


Date of Birth    - 23/01/1984    (enter value in cell A1)

Today's Date   - 06/05/2014    (enter value in cell B1)

=DATEDIF(L2,M2,"Y")&" Years, "&DATEDIF(L2,M2,"YM")&" Months, and "&DATEDIF(L2,M2,"MD")&" Days"


The output of the above formula will be -

30 Years, 4 Months, and 13 Days



=DateDif(A1,B1,"Y") = output will be number of years (Y)

=DateDif(A1,B1,"M") = output will be number of months (M)
=DateDif(A1,B1,"D") = output will be number of days (D)
=DateDif(A1,B1,"YM") = output will be number of calendar months from start year, here the months will be for current year
=DateDif(A1,B1,"YD") = output will be number of calendar days from start year, here the days will be for current year
=DateDif(A1,B1,"MD") = output will be number of calendar days from start month, here the days will be for current month


Above combination of codes can be used at different situations, one example we saw above -

1. To find the Age
2. Remaining days to your wedding
3. Days remaining to Expiring warranty or maintenance
4. Total employment experience
5. Property Agreement going to expire
...... and more

Done....


*all codes in this blog are tested on Excel 2010

Friday, April 4, 2014

Find first and last date of any month

You can find the first date of any month in three different conditions mentioned below:

First Day of any month - 


Enter Month and Year in "cell D4" e.g. December-2014 and use the below formula in "cell E4" to get the first date of the month


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



Enter any date value in "cell D5" e.g. 4-Apr-2014 and use the below formula 

in "cell E5" to get the first date of the month

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



Enter any Month name in "cell D6" e.g. February and use the below formula 

in "cell E6" to get the first date of the month

=(D6&"/1")+0



Enter any Year in "cell D7" e.g. 2014 and use the below formula 

in "cell E7" to get the first date of the month

=DATE(D7,1,1)



Below is the screenshot for the above formulas :










Last Day of month - 

Below formula is used to get the last date of any month, based on the selected date

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

here for e.g., if we say B3 = 5/6/2014, then output of above formula will be 5/31/2014



Last Day of Previous month - 

Below formula is used to get the last date of previous month, based on the selected date

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


here for e.g., if we say B3 = 5/6/2014, then output of above formula will be 4/30/2014


These formulas can be used in different conditions where formula based data analysis is required and the data keeps changing based on different dates.

e.g. Case :

You can find the first date and keep adding that date by 1 to get the next dates of the month.

Done......