+ Reply to Thread
Results 1 to 5 of 5

Assign current cell to a variable and re-select

Hybrid View

  1. #1
    Forum Contributor
    Join Date
    04-13-2006
    Location
    London
    Posts
    102

    Assign current cell to a variable and re-select

    I can't believe I don't know how to do this! I must be having a mental block!

    I want to assign the active cell reference to a variable, then when my macro finishes, the variable's reference is made the active cell again.

    For example, if F2 is my current cell, I want the variable CurCell to store the reference F2. When my macro finishes, I want the active cell to be the CurCell reference.

    This code doesn't work, but this is what I'm trying to do:

    Dim CurCell as Range
    
    ActiveCell.Select
    CurCell = ActiveCell.Range("A1")
    
    ....some code
    ....
    ....
    
    Range(CurCell).Select
    I can't think - what am I doing wrong?

    Thanks!

  2. #2
    Forum Contributor
    Join Date
    03-13-2005
    Posts
    6,195
    Quote Originally Posted by Cumberland
    I can't believe I don't know how to do this! I must be having a mental block!

    I want to assign the active cell reference to a variable, then when my macro finishes, the variable's reference is made the active cell again.

    For example, if F2 is my current cell, I want the variable CurCell to store the reference F2. When my macro finishes, I want the active cell to be the CurCell reference.

    This code doesn't work, but this is what I'm trying to do:

    Dim CurCell as Range
    
    ActiveCell.Select
    CurCell = ActiveCell.Range("A1")
    
    ....some code
    ....
    ....
    
    Range(CurCell).Select
    I can't think - what am I doing wrong?

    Thanks!
    try
    Dim CurCell As Range
    Set CurCell = ActiveCell
     .. your code here
    Application.Goto CurCell

  3. #3
    Forum Contributor
    Join Date
    04-13-2006
    Location
    London
    Posts
    102
    Thanks - that would seem to do the trick!

    I also found a workaround by using Row and Column with Cells:

    CurRow = ActiveCell.Row
    CurColumn = ActiveCell.Column
    
    ...code...
    ...code...
    
    Cells(CurRow, CurColumn).Activate

  4. #4
    Forum Contributor
    Join Date
    03-13-2005
    Posts
    6,195
    Good to see, and thanks for the response
    Quote Originally Posted by Cumberland
    Thanks - that would seem to do the trick!

    I also found a workaround by using Row and Column with Cells:

    CurRow = ActiveCell.Row
    CurColumn = ActiveCell.Column
    
    ...code...
    ...code...
    
    Cells(CurRow, CurColumn).Activate

  5. #5
    Registered User
    Join Date
    09-23-2006
    Posts
    9
    Thanx Guys,
    I was looking for a way to do this

+ 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