First of all, a literal understanding that target is the meaning of the goal, we can also understand that the chosen object, in fact, is the target targeted to operate.
First, target Application scope
Target can appear in two places, one for events and two for VBA code.
For example, in the event Worksheet_selectionchange (ByVal target as Range), the target object is present, which treats the range of cells as a target.
The Target code in VBA, such as: target.address (0, 0), is used in this way.
Second, target application code example
Example code One
Private Sub Worksheet_selectionchange (ByVal Target as Range)
If not Application.intersect (Target, Union (range ("a1:a10"), Range ("C1:C10")) are nothing Then
MsgBox "you selected" & Target.Address (0, 0) & "Cell"
End If
End Sub
Code Explanation:
Displays the selected cell address in a message box when you select the worksheet A1 to A10,c1 to the C10 cell.
The 2nd line of code uses the Intersect method to determine whether the selected cells overlap A1 to a10,c1 to C10 cells, if overlapping indicates that the selected cells are in the A1 to the A10,C1 range of cells. The Intersect method returns a Range object that represents two or more ranges of overlapping rectangular regions, and the syntax is as follows:
Example code two
You can limit the trigger condition to a range by using the cell's Column property and the row property, as shown in the following code.
Private Sub Worksheet_change (ByVal Target as Range)
If Target.Column = 1 and Target.Row < Then
Target.Offset (, 1) = Val (Target) * 3
End If
End Sub
Copy Code Resolution:
When you change the A1 of a worksheet to A10 cell, if you enter a number, the value is written in the corresponding B-column cell multiplied by 3.
Line 2nd uses the column property to limit the trigger condition to column 1th, using the row property to limit the trigger condition to the line 10th, which is the range of A1 to A10.
Example code Three
Private Sub Worksheet_followhyperlink (ByVal Target as Hyperlink)
' Target is not an area, it's a hyperlink.
End Sub
Example code Four
if ((target.row=4) and (target.column=3)) Then
Calendar1.visible = True
Target.column=3 ' indicates that the selected cell is in column 3rd
Target.row=4 ' indicates that the selected cell is on line 4th
Again, Target.Offset (0, 1) =4 indicates that the selected cell is offset to the right of the 1 column position.