Home

Introduction to Cells

 

Introduction to Cells Data Entry

Data entry consists of adding one or more values into one or more cells. This can be done manually, automatically, or programmatically.

Using the Active Cell

Before manually entering data into a cell, the user can click a cell to select it. The cell that is selected has thick borders:

After selecting the intended cell, the user can press the necessary key(s) on the keyboard to create or assign the desired value.

The selected cell is referred to as the active cell. In the previous lesson, we saw that the active cell is represented by an object called ActiveCell. Therefore, to programmatically add a value to the active cell, assign that value to this object.

Programmatically Referring to a Cell

In the previous lesson, we saw different ways of referencing a cell. Here is one of the examples we used:

Sub Exercise()
    Workbooks.Item(1).Worksheets.Item("Sheet1").Range("D6")
End Sub

To enter value into a particular cell, reference it and then assign the desired value to it.

Practical LearningPractical Learning: Introducing Data Entry

  1. Start Microsoft Excel
  2. On the Ribbon, click Developer
  3. In the Code section, click Record Macro
  4. Set the Macro Name to CreateWorkbook
  5. In the Shortcut Key text box, type W to get Ctrl + Shift + W
     
    Record Macro
  6. Click OK
  7. On the Ribbon, click Stop Recording
  8. In the Code section of the Ribbon, click Macros Macros
  9. In the Macro dialog box, make sure CreateWorkbook is selected and click Edit
  10. Change the code as follows:
     
    Option Explicit
    
    Sub CreateWorkbook()
        ' CreateWorkbook Macro
        ' This macro is used to create a workbook for the
        ' Georgetown Dry Cleaning Services
    
        ' Keyboard Shortcut: Ctrl+Shift+W
        
        Rem Just in case there is anything on the
        Rem worksheet, delete everything
        Range("A:K").Delete
        Range("1:20").Delete
        
        Rem Create the sections and headings of the worksheet
        Range("B2") = "Georgetown Dry Cleaning Services"
        Range("B5") = "Order Identification"
        Range("B6") = "Receipt #:"
        Range("G6") = "Order Status:"
        Range("B7") = "Customer Name:"
        Range("G7") = "Customer Phone:"
        
        Range("B9") = "Date Left:"
        Range("G9") = "Time Left:"
        Range("B10") = "Date Expected:"
        Range("G10") = "Time Expected:"
        Range("B11") = "Date Picked Up:"
        Range("G11") = "Time Picked Up:"
              
        Range("B13") = "Items to Clean"
        Range("B14") = "Item"
        Range("D14") = "Unit Price"
        Range("E14") = "Qty"
        Range("F14") = "Sub-Total"
    
        Range("B15") = "Shirts"
        Range("H15") = "Order Summary"
        Range("B16") = "Pants"
        Range("B17") = "None"
        Range("H17") = "Cleaning Total:"
        Range("B18") = "None"
        Range("H18") = "Tax Rate:"
        Range("I18") = "5.75"
        Range("J18") = "%"
        Range("B19") = "None"
        Range("H19") = "Tax Amount:"
        Range("B20") = "None"
        Range("H20") = "Order Total:"
        
        Rem Change the widths and heights of some columns and rows
        Rem In previous lessons, we learned all these things
        Range("E:E, G:G").ColumnWidth = 4
        Columns("H").ColumnWidth = 14
        Columns("J").ColumnWidth = 1.75
        
        Rows("3").RowHeight = 2
        Range("8:8, 12:12").RowHeight = 8
        
        Rem Hide the gridlines
        ActiveWindow.DisplayGridlines = False
    End Sub
  11. To return to Microsoft Excel, click the View Microsoft Excel button View Microsoft Excel
  12. To fill the worksheet, press Ctrl + Shift + W
     
    Georgetown Dry Cleaning Services
  13. Return to Microsoft Visual Basic
 
 
 

Home Copyright © 2008-2010 FunctionX, Inc. Next