learn microsoft excel

  How to Access Excel Worksheet Cells with a Macro Using the Range Property

Excel 2007 Excel 2003 Home Macros Excel 2003 Excel 2010
About Us Free Ebook Offline Training Blog Excel VBA Books

Before you can start performing calculations with your Excel data, you obviously have to enter data into the worksheet. Now if you wish to enter data with the help of a macro you need to know how to access a worksheet cell like A1 or a range of cells like A1:C1. The 'range' property helps you to access a single cell or a range of cells. Later you can define whether a cell can contain text, number, currency, formulas or functions.
  • Click on the 'Developer' Tab
  • From the 'Code' group select Visual Basic
  • The Microsoft Visual Basic window pops up
  • Click on 'Insert' and select 'Module'.
  • In the white workspace area type 'Sub macroname()'. Select a macro-name that is short and easy to remember and describes well what the macro will do
  • Press enter and you will notice that the application automatically adds 'End Sub'
  • Between the 'Sub macroname ()' and the 'End Sub' you will write the code that will execute what the macro is supposed to do
We enter the following code for example:
Sub range_propert_to_access_worksheet_cells()
Range("A3") = "Name"
Range("B3") = "Salary"
End Sub

When we click on the run arrow-like button (>) the macro executes the code and after minimizing the  MS-Visual Basic Window  we can  observe  that the text  'Name'  and  'Salary'  have been plced in the appropriate worksheet cells 'A1' and 'B1'.
Let's have a look at the MS Excel VBA training video.




Excel 2007 Excel 2003 Macros Excel 2007 Macros Excel 2003 Excel 2010
About Us Free Ebook Offline Training Blog Excel VBA Books