tailieunhanh - Introduction to using macros in Microsoft Excel 2003 phần 4

xóa các nội dung của tất cả các tế bào trên Sheet2 của bảng tính đang hoạt động. Lưu ý: Các tài sản tế bào là rất hữu ích khi viết một macro để lặp thông qua một loạt các tế bào. 8,3 dòng và cột Có một vài tài sản được gọi là dòng và cột cho phép bạn làm việc với các hàng hoặc cột toàn bộ. Cột Ví dụ dòng tham chiếu (4) Hàng Cột (4) Columns ("D") | Example 3 Worksheets Sheet2 . clears the contents of all the cells on Sheet2 of the active workbook. Note The Cells property is very useful when writing a macro to loop through a range of cells. Rows and Columns There are a couple of properties called Rows and Columns that enable you to work with entire rows or columns. Reference Refers to Rows 4 Row 4 Rows All the rows on active worksheet Columns 4 Column D Columns D Column D Columns All the columns on active worksheet Example Worksheets Week4 .Rows 2 . True gives a bold format to the contents of all the cells in the second row of the sheet Week4 of the active workbook. Note It is possible to work with several rows or columns at once by using the Union method not discussed in this document . Named ranges Sometimes it is easier to deal with a range when it has a name rather than have to use A1 notation. A name can be given to the range before the macro is written or the macro can assign the name to the range. Name given to range outside the macro To give a name to a range select the range of cells click in the Name box at the left-hand end of the formula bar type a name and press the Enter key. Suppose the name Week2 has already been given to the cells F12 F18 on the sheet June in the workbook Year2000. Example 1 Range June Week2 . True will give a bold format to the cells in the named range Week2. Guide 39 Introduction to using macros in Microsoft Excel 2003 27 Example 2 If Year2000 is the active workbook and June is the active worksheet then Range Week2 . True will give a bold format to the cells in the named range Week2. Name given to range as part of the macro A name can be assigned to a range from within a macro as in the example below Workbooks . _ Name Week2 _ RefersTo June D1 D10 and then the instruction Range Week2 . True will work as before. Multiple ranges It can be useful to refer to .