If, In a macro, a desired cell is located , how can I go about saving the location of that cell to be used later in the macro?
If, In a macro, a desired cell is located , how can I go about saving the location of that cell to be used later in the macro?
The easiest way is to use a range variable.
The Dim statement can be put anytime before the second line. Most folks put all their declarations at the start of the Macro.Please Login or Register to view this content.
Anytime later, in the same macro (see Help system "scope"), myRange will refer to the stored value as in:
Note that myRange is a Range object. It refers to the cell, NOT to the value in the cell.Please Login or Register to view this content.
To refer to the value in the cell, use.Please Login or Register to view this content.
If the cell contains a formula,refers to the value in the cell. If you want the formula (as a string) usePlease Login or Register to view this content.
Please Login or Register to view this content.
It sounds like you are new to programming in VB. Selecting is seldom needed. The Macro recorder uses it frequently, but it can ususally be ommited. For example
will set myRange to [myBook]Sheet 1!A1:B4 without selecting.Please Login or Register to view this content.
That was exactly what I needed. Thanks Mikerickson.
You're welcome
There are currently 1 users browsing this thread. (0 members and 1 guests)
Bookmarks