Вы находитесь на странице: 1из 3

A 1 2 3 Referring to things in Excel 4 A workbook 5 A worksheet 6 A cell or range in A1 convention 7 Several cells or ranges 8 A range in R1C1 convention 9 A cell

in R1C1 convention 10 A range with a name 11 An entire column or row in A1 convention 12 An entire column or row in R1C1 convention 13 A number of rows with fixed (i.e., known) row numbers 14 A number of rows with variable row numbers 15 The 3rd row of a range (C5:G5 here) 16 All cells in a worksheet 17 A cell relative to a specified cell (C16 here) 18 A range relative to a specified range (D8:F13 here) 19 The currently selected object (cell, range, etc.) 20 The workbook containing the procedure being executed 21 The currently active workbook 22 The currently active cell (may be part of selected range) 23 Workbooks("MyBook.xls")

Appendix B: VBA Quick Reference

Worksheets("Sheet1") or Sheets("Sheet1") Range("A1") or Range("A1:C5") Range("A1,C5,D11") or Range("A1:C5,F6,D2:E5") Range(Cells(1,1): Cells(5,10)) Cells(1, 5) Range("RangeName") Columns("D:D") or Rows("6:6") Columns(1) or Rows(6) Rows("6:100") Rows(startRow & ":" & endRow) Range("C3:G15).Rows(3) Worksheets("Sheet1").Cells Range("F15").Offset(1, -3) Range("B5:D10").Offset(3,2) Selection ThisWorkbook ActiveWorkbook ActiveCell

A 24 25 Using some common properties 26 To retrieve the value (contents) of a cell or range 27 To assign values to a cell or range 28 To assign values to a named cell or range 29 To retrieve the text in a cell 30 To get the column or row number of a cell 31 To get the number of the first column of a range 32 To enter a formula into a cell or range in A1 convention 33 To enter a formula into a cell or range in R1C1 convention 34 To name a cell or range 35 To rename a worksheet 36 Hide or unhide a worksheet 37 38 Using some common methods 39 Activate a worksheet 40 Select the entire active worksheet 41 Select a range 42 Activate a cell within a selected range 43 Clear current selection (worksheet, range, etc.) 44 Clear both contents and format of a range 45 Clear contents (but not format) of a range 46 Clear format (but not contents) of a range Sheets("Sheet1").Activate Cells.Select Range("A1:C12").Select Range("F6").Activate Selection.Clear Range("D1:D7").Clear Range("D1:D7").ClearContents Range("D1:D7").ClearFormats cellVal = Cells(1,5).Value Range("A1:C3"). Value = 123 Range("RangeName"). Value = 123 cellText = Range("A1").Text

Range("C5").Column or Range ("C5").Row or Selection.Column Range ("F5:H10").Column or Selection .Column Range("A3").Formula = "=Sum(A1:A2)" Range("A3").FormulaR1C1 = "=SUM(R[-2]C:R[-1]C)" Range("A1:C3"). Name = "RangeName" Worksheets("Sheet3").Name = "Stock Options" Worksheets("Sheet1").Visible = False or True

A 47 Delete several rows or columns 48 Copy a range and paste at a different location 49 Insert a row before row 4 50 Insert a worksheet before the active sheet 51 Delete a worksheet 52 53 54

B Rows ("6:10").Delete or Columns("7:12").Delete Range("A1:C12").Copy Range("D1") Rows(4).Insert Sheets.Add or Worksheets.Add Worksheets("Sheet1").Delete