macros excel

8

Upload: zenobia-sukhia

Post on 27-Nov-2014

166 views

Category:

Education


4 download

DESCRIPTION

use of macros in excel

TRANSCRIPT

Page 1: MACROS excel
Page 2: MACROS excel

Most users have come across the word MACRO, one time

or another using Excel. A macro is a recording of sorts, that

stores your actions, step by step. Macros are used to

eliminate the need to repeat the steps of common tasks

over and over. Tasks such as adding or removing rows and

columns, selecting a range of cells, or changing textcolor,

fonts etc. In Excel, macros are written in Visual Basic for

Applications (VBA). For those who cannot write VBA code,

Excel allows you to record a series of steps – using

keyboard and mouse – that Excel then converts into a

macro.

Page 3: MACROS excel
Page 4: MACROS excel

Open a blank Excel Document and click on the VIEW-Ribbon. All the way to the right is the Macro Button. Click on the little black arrow underneath the Macro Icon, and choose: “Use Relative References”.

Click the little black arrow (under the macro icon) again. This time, choose “Record Macro”. Call it “First”, Click OK.

Page 5: MACROS excel

Now, Click on a Cell and type.

Select a sample of cells around the text you wrote.

Click on the HOME-Ribbon, and set text color and background color.

Click the little black arrow underneath the macro icon, once more, choose “Stop Recording”.

Page 6: MACROS excel

Highlight a new cell.

Click on the Macro Icon, showing a list of available macros and Click RUN.

What you see is that Excel now replicates our steps, on a new set of cells. Choose a different Cell, and try it again to see that it works.

Page 7: MACROS excel

To see what the code looks like, click the Macro Icon again, choose the macro and click EDIT.

This will open the VBA editor and show your macro:Sub First()'' First Macro''ActiveCell.FormulaR1C1 = "This is my first Macro Recording"ActiveCell.SelectSelection.Font.Bold = TrueWith Selection.Font.Color = -16776961.TintAndShade = 0End WithActiveCell.Range("A1:D3").SelectWith Selection.Interior.PatternColorIndex = xlAutomatic.Color = 65535.TintAndShade = 0.PatternTintAndShade = 0End WithEnd Sub

Page 8: MACROS excel