Objects, Properties and Methods Workout
- 03:46
Workout demonstrating the use of the current region property and application of the copy method.
Transcript
In this workout, we are required to write VBA code to enter the words My Cell in cell C7.
In order to write our VBA code, we must go into the Visual Basic editor via developer and Visual Basic.
In the Visual Basic Editor, the Visual Basic Editor window is blank.
And to write our code, we must first insert a new module.
We can do this via insert and module by default.
Our new module is called Module 1.
We can change this in the name property and I'll call it workout.
Start your procedure with the word sub and give your procedure a descriptive title without any spaces or special characters.
Let's call our procedure workout one.
After pressing enter, you'll notice that the words end sub are automatically put after one spare line.
We will write our procedure code in between the Subwork out one and the end of our sub procedure.
Sub is shorthand for public sub.
The procedure is available to any other procedure in the file.
We can proceed the word sub with the word private.
This is purely optional and a private sub indicates that the procedure is only available to other procedures in the same module.
In workout one, we need to assign the value property the value of my cell.
Remember, a cell doesn't have to be selected in the front end of Excel to apply VBA code to it.
We can type range and in quotes, C7 to refer to the range object cell C7.
We want to assign the value property, my cell value and the value property is assigned the words my cell.
As this is text, we should put it within the quotation marks.
Let's press enter and we've completed our code going back to the front end of Excel.
We can test this out and run our procedure.
I'll select developer macros and we can see our code here work out one.
Clicking on run. We will execute our procedure and as we anticipated, the words my cell have been added into cell C7.
The range object C7 has had its value property updated and applied to it.
The words My Cell.