+ Reply to Thread
Results 1 to 4 of 4

Save A Cell Location

  1. #1
    Registered User
    Join Date
    04-30-2004
    Posts
    78

    Talking Save A Cell Location

    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?

  2. #2
    Forum Expert mikerickson's Avatar
    Join Date
    03-30-2007
    Location
    Davis CA
    MS-Off Ver
    Excel 2011
    Posts
    6,229
    The easiest way is to use a range variable.

    Please Login or Register  to view this content.
    The Dim statement can be put anytime before the second line. Most folks put all their declarations at the start of the Macro.
    Anytime later, in the same macro (see Help system "scope"), myRange will refer to the stored value as in:
    Please Login or Register  to view this content.
    Note that myRange is a Range object. It refers to the cell, NOT to the value in the cell.
    To refer to the value in the cell, use
    Please Login or Register  to view this content.
    .
    If the cell contains a formula,
    Please Login or Register  to view this content.
    refers to the value in the cell. If you want the formula (as a string) use
    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

    Please Login or Register  to view this content.
    will set myRange to [myBook]Sheet 1!A1:B4 without selecting.

  3. #3
    Registered User
    Join Date
    04-30-2004
    Posts
    78
    That was exactly what I needed. Thanks Mikerickson.

  4. #4
    Forum Expert mikerickson's Avatar
    Join Date
    03-30-2007
    Location
    Davis CA
    MS-Off Ver
    Excel 2011
    Posts
    6,229
    You're welcome

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1