After you learn from previous lesson regarding the Object, Properties and Adjective, we will discuss about METHOD.
Second Pattern
OBECT.METHOD=TRUE OR FALSE (OPTIONAL)
For example, I will delete the sheet1.
Sheet1 = object
Delete = Method
Definition of Term
Method
It is just a Verb.
This is an action on what you want to do.
Example:
Save
Copy
Paste
Open and many more
So, let's try another example.
Sub MySecondCode()
Sheets("SHEET2").Delete ' Sheet2 will be deleted
End Sub
Explanation:
Again, Sheets () is a built-in properties in VBA.
Assign a name of sheet inside the parenthesis. Since its a constant value, you need to put "".
If it's variable, no need for "".
Another example, using Activate and Select.
Sub MyThirdCode()
Sheets("Sheet1").Activate ' Sheet1 will be activated. Note: Be sure that you know the name of your worksheet
Activesheet.Range("B15").Select 'cell B15 of the active sheet will be selected. Activesheet is also built-in object in vba.
End Sub
Homework:
Make a table in sheet1
Copy the table to sheet2.
Make the border of your table thicker.
Make the front Bold and font color yellow.
Don't use record macro. Create your own code.
In the next article, i will teach you on how to use Variable.
No comments:
Post a Comment