Friday, June 13, 2014

Excel : Visual Basic - Macro Recorder

The Macro Recorder, a very useful tool included in Excel VBA, records every task you perform with Excel. All you have to do is record a specific task once. Next, you can execute the task over and over with the click of a button. The Macro Recorder is also a great help when you don't know how to program a specific task in Excel VBA. Simply open the Visual Basic Editor after recording the task to see how it can be programmed.

Record a Macro :-

1. On the Developer tab, click Record Macro.



2. Enter a name.

3. Select This Workbook from the drop-down list. As a result, the macro will only be available in the current workbook.




















Note: if you store your macro in Personal Macro Workbook, the macro will be available to all your workbooks (Excel files). This is possible because Excel stores your macro in a hidden workbook that opens automatically when Excel starts. If you store your macro in New Workbook, the macro will only be available in an automatically new opened workbook.

4. Click OK.

5. Right mouse click on the active cell (selected cell). Be sure not to select any other cell! Next, click Format Cells.



6. Select Percentage.



7. Click OK.

8. Finally, click Stop Recording.



Congratulations. You've just recorded a macro with the Macro Recorder!

Run a Recorded Macro :-

Now we'll test the macro to see if it can change the number format to Percentage.

1. Enter some numbers between 0 and 1.

2. Select the numbers.



3. On the Developer tab, click Macros.



4. Click Run.



Result :-



See the Macro :-

To take a look at the macro, open the Visual Basic Editor.



Visual Basic Editor

Note: the macro has been placed into a module called Module1. Code placed into a module is available to the whole workbook. That means, you can select Sheet2 or Sheet3 and change the number format of cells on these sheets as well. Remember, code placed on a sheet (assigned to a command button) is only available for that particular sheet.

Excel : Visual Basic - Create a Macro

With Excel VBA you can automate tasks in Excel by writing so called macros. In this chapter, learn how to create a simple macro which will be executed after clicking on a command button. First, turn on the Developer tab.

Developer Tab :-

To turn on the Developter tab, execute the following steps.

1. Right click anywhere on the ribbon, and then click Customize the Ribbon.


2. Under Customize the Ribbon, on the right side of the dialog box, select Main tabs (if necessary).

3. Check the Developer check box.


4. Click OK.

5. You can find the Developer tab next to the View tab.


Command Button :-

To place a command button on your worksheet, execute the following steps.

1. On the Developer tab, click Insert.

2. In the ActiveX Controls group, click Command Button.


3. Drag a command button on your worksheet.

Assign a Macro :-

To assign a macro (one or more code lines) to the command button, execute the following steps.

1. Right click CommandButton1 (make sure Design Mode is selected).

2. Click View Code.


The Visual Basic Editor appears.

3. Place your cursor between Private Sub CommandButton1_Click() and End Sub.

4. Add the code line shown below.
Range ("A1").Value = "Hello"


Note: the window on the left with the names Sheet1, Sheet2 and Sheet3 is called the Project Explorer. If the Project Explorer is not visible, click View, Project Explorer. To add the Code window for the first sheet, click Sheet1 (Sheet1).

5. Close the Visual Basic Editor.

6. Click the command button on the sheet (make sure Design Mode is deselected).

Result:


Visual Basic Editor

To open the Visual Basic Editor, on the Developer tab, click Visual Basic.


The Visual Basic Editor appears.


Date & Time Functions in Microsoft Excel

What is the use of Day formula?

Tells you the day of month from a given date


Syntax of Day formula:
day(of this date)

Examples of Excel Day formula:
day("12/31/1981") = 31
day(today()) = current day


What is the use of Hour formula?

Tells you the hour from a given time


Syntax of Hour formula:
hour(at this time)

Examples of Excel Hour formula:
hour("11:30") = 11
hour(now()) = current hou



What is the use of Minute formula?

Tells you the minutes from a given time


Syntax of Minute formula:
minute(at this time)

Examples of Excel Minute formula:
minute("11:30") = 30
minute(now()) = current minutes


What is the use of Month formula?

Tells you the month from a given date


Syntax of Month formula:
month(of this date)

Examples of Excel Month formula:
month("12/31/1981") = 12
month(today()) = current month


What is the use of Networkdays formula?

Tells you how many working days are there between 2 given dates


Syntax of Networkdays formula:
networkdays(from this date, to this date, [add this holidays as well])

Examples of Excel Networkdays formula:
networkdays("12/1/2008","12/31/2008") = 23
networkdays(TODAY(),TODAY()+30) = total working days in next 30 days
What is the use of Now formula?

Today's date along with current time


Syntax of Now formula:
now()

Examples of Excel Now formula:
now() = today's date along with current time




What is the use of Second formula?

Tells you the seconds from a given time


Syntax of Second formula:
second(at this time)

Examples of Excel Second formula:
second("11:30:45") = 45
second(now()) = current seconds



What is the use of Today formula?

Today's date


Syntax of Today formula:
today()

Examples of Excel Today formula:
today() = today's date



What is the use of Weekday formula?

Tells you the day of week from a given date


Syntax of Weekday formula:
weekday(of this date)

Examples of Excel Weekday formula:
weekday("12/12/1981") = 7
weekday(today()) = current day of week


What is the use of Year formula?

Tells you the year from a given date


Syntax of Year formula:
year(of this date)

Examples of Excel Year formula:
year("12/31/1981") = 1981
year(today()) = current year

Logical & Reference Functions in Microsoft Excel


What is the use of And formula?

Checks whether all conditions are passed or not


Syntax of And formula:
and(list of conditions)

Examples of Excel And formula:
and(true, false) = false
and(true, true) = true


What is the use of Countblank formula?

Counts blank cells in a given list


Syntax of Countblank formula:
countblank(in this list)

Examples of Excel Countblank formula:
countblank(list) = number of blank cells in the list 

What is the use of Countif formula?

Counts of items in a list matching a condition


Syntax of Countif formula:
countif(in this range, values meeting this criteria)

Examples of Excel Countif formula:
countif(A1:A20, 1) = counts how many cells have "1" 
countif(A1:A20, "<3") = counts how many cells have less than 3

What is the use of If formula?

Fetches one of the two values based on a condition


Syntax of If formula:
if(is-this-true?, do this, or this)

Examples of Excel If formula:
if(5<10,"hello","world") = hello
if(5>10,"hello","world") = world

What is the use of Large formula?

Finds the nth largest number in a list


Syntax of Large formula:
large(from this list, nth largest number)

Examples of Excel Large formula:
large(list, 2) = 2nd largest number in the list


What is the use of Max formula?

Finds the maximum of a given list of numbers


Syntax of Max formula:
max(of this list of numbers)

Examples of Excel Max formula:
max(1,2,3) = 3
max(A1:A20) = maximum value in the range A1:A20


What is the use of Min formula?

Finds the minimum of a given list of numbers


Syntax of Min formula:
min(of this list of numbers)

Examples of Excel Min formula:
min(1,2,3) = 1
min(A1:A20) = minimum value in the range A1:A20

What is the use of Not formula?

Negates a logical value


Syntax of Not formula:
not(this logical value)

Examples of Excel Not formula:
not(false) = true
not(not(false)) = false

What is the use of Or formula?

Checks whether any condition is met


Syntax of Or formula:
or(list of conditions)

Examples of Excel Or formula:
or(true, false) = true
or(false, false) = false

What is the use of Small formula?

Finds the nth smallest number in a list


Syntax of Small formula:
small(from this list, nth smallest number)

Examples of Excel Small formula:
small(list, 2) = 2nd smallest number in the list

What is the use of Sumif formula?

Sums items in a list matching a condition


Syntax of Sumif formula:
sumif(in this range, values meeting this criteria, [sum-this-range])

Examples of Excel Sumif formula:
sumif(A1:A20, 3) = sums the cells with a value of "3" 
sumif(A1:A20, 3, b1:b20) = same as above but adds values in B1:B20

What is the use of Vlookup formula?

Searches a list for a value you are looking for and returns a corresponding value


Syntax of Vlookup formula:
vlookup(this value, in this list, and get me value in this column, [is-my-list-sorted?])

Examples of Excel Vlookup formula:
vlookup("John", list, 2, false) = finds where Jon is in the list and returns the value in the 2nd column

Text Functions in Microsoft Excel - Join Strings (use the & Operator)

Join Strings :-


To join strings, use the & operator.







Note: to insert a space, use " "




Thursday, June 12, 2014

Password Protect Particular Column or Row in Excel

How to Password protect a particular Column Or Row in Excel?

Step 1: 
Select all cells in current worksheet with pressing the Ctrl key and A key together.

Step 2: 
Right click, and select the Format Cell item from the context menu.


Step 3: 
In the Format Cells dialog box, uncheck the Locked option under Protection tab, and click OK button. See the following screen shot:


Step 4:
Select cells and ranges that you want to lock.

Step 5: 
Right click selected ranges, and select the Format Cell item from the context menu.


Step 6: 
In the Format Cells dialog box, check the Lock option under Protection tab, and click OK.


Step 7: 
Click the Protect Sheet button in the Changes group under Review tab.

Step 8: 
In the Protect Sheet dialog box, enter a password in the blank box under Password to unprotect sheet: See the following screen shot:

Step 9: 
Confirm Password dialog box pops up, please reenter the password again.


Step 10: Click OK.

Then it locks and protects only selected cells and ranges in current worksheet, while unselect ranges are editable.