Associating methods with objects
So, what is a method, and what is its connection with objects? Objects have properties, as we have seen, while a method is something an object does. A method is a specific piece of code you type after an object. It's like an instruction to the object: copy (the cell object), print (the sheet object), or select (the range object). In this recipe, we will use three basic methods: Activate
, Copy
, and ClearContents
. In this recipe, we will copy content from one selection to another.
Getting ready
Make sure that a blank workbook is active in Excel. Type the words Monday
, Tuesday
, and Wednesday
into cells A1, B1, and C1, respectively.
How to do it…
- Press Alt + F11 to activate the VBA Editor.
- In the Project window of Explorer, double-click Sheet1 under Book1. The corresponding code window will appear.
- Type the following code into the code window:
Sub CopyCell() Worksheets("Sheet1...