VBA Target.Address

Written by

Mel Jenkins

Reviewed by

Steve Rynearson

Last updated on August 10, 2022

This article will demonstrate the use of VBA Target.Address.

vba target address selection change event

Target.Address

Target is the given name of the Range object variable that is contained in the argument of Worksheet Object Events, such as Worksheet_SelectionChange.

This event is triggered when you move from one cell to another in your worksheet.

 

To create a Worksheet Event, on the VBE Editor, select the appropriate worksheet and then, in the Object drop down box, select Worksheet.

vba target address worksheet

 

Consider the following code:

Private Sub Worksheet_SelectionChange(ByVal Target As Range)
  If Target.Address = "$F$2" Then
    Range(Target.Address).Font.Bold = True
  End If
End Sub

Whenever you move your cursor this event will run and the IF Statement will test if the selected cell is F2. If it is, the cell will be set to Bold.

 

NOTE: The Target.Address is an absolute ($F$2), so when checking to see if you are on the appropriate cell, you must use $ signs in your string (“$F$2”).

The Target Range (and therefore the Target.Address method) is also avaialable with the Worksheet_Change; Worksheet_BeforeDoubleClick and Worksheet_BeforeRightClick event procedures in your Worksheet object.

vba-free-addin

VBA Code Examples Add-in

Easily access all of the code examples found on our site.

Simply navigate to the menu, click, and the code will be inserted directly into your module. .xlam add-in.

(No installation required!)

Free Download

Return to VBA Code Examples