Microsoft Office Tutorials and References
In Depth Information Goto method
This method selects a given range in any workbook. (It can also select a Visual Basic procedure.)
The syntax is:
Application.Goto( Reference , Scroll )
The optional Reference parameter specifies the destination. It can be a Range object, a string
that contains a cell reference in R1C1-style notation, or a string that contains a Visual Basic
procedure name. If the argument is omitted, the destination is the destination used in the previous
call to GoTo.
The optional Scroll parameter should be set to True to scroll through the window so that the
upper-left corner of the destination appears in the upper-left corner of the window. The default is
False , which means the destination will not move if it was visible within the window, or else it
will appear at the bottom of the window if it was not visible.
For example, to select the range B5:C6 in the active worksheet, we can write:
Application.Goto Reference:=Range("B5:C6")
Application.Goto Reference:="R5C2:R6C3"
The GoTo method also works in conjunction with the PreviousSelections array. In particular, the
Application object has a PreviousSelections property that returns an array of Range objects
referencing the previous four ranges selected. The syntax is:
where Index is a number between 1 and 4.
Each time the user selects a range or cell either by using the Name box or the Go To command (on
the Edit menu), or the Goto method is called in code, the current range (before the action takes
place) is added to the top (index 1) of the PreviousSelections array and the other items in the array
are moved down one index value. (The item in position 4, of course, drops out of the array.)
As a simple illustration, consider the code:
Application.Goto Sheet1.Range("A1")
ActiveCell.Value = 1
Application.Goto Sheet2.Range("A1")
ActiveCell.Value = 2
which fills the first cell on each of two sheets, using the GoTo method to add the cell ranges to the
PreviousSelections array.
Now the following line will alternate between the two cells when executed repeatedly:
Application.Goto Application.PreviousSelections(1)
Note that the GoTo method differs from the Select method in several ways:
Both methods select the given range, but the Select method does not activate the sheet
upon which the new selection is made (if it is not already active).
The Select method does not have a Scroll argument.
Search JabSto ::

Custom Search