Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8471327
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T16:45:58+00:00 2026-06-10T16:45:58+00:00

This question is somewhat related to this one: VBA: What happens to Range objects

  • 0

This question is somewhat related to this one: VBA: What happens to Range objects if user deletes cells?

Is there any way to reliably test for identity of two cell references, and, more importantly, to store cell references over time?

Consider the following example:

Sub TestCellIdentity ()

   Dim r As Range
   Set r = Application.ActiveCell
   r.Value = "Some Value"

   Dim ws As Worksheet
   Set ws = r.Worksheet

   Dim n As String
   n = ws.Name

   Dim c As Range
   Set c = Worksheets (n).Cells (r.Row, r.Column)

   MsgBox ("ActiveCell ptr: " & CStr (ObjPtr (r)) & "Value: " & r.Value _
     & "; Indirect access ptr: " & CStr (ObjPtr (c)) & " Value: " & c.Value)
End Sub

Running the example shows that ObjPtr (r) and ObjPtr (c) are different, even though they refer to the same cell. What is worse, it seems to me (from some tests) that I cannot assume that two cell objects (object references) with the same ObjPtr reference are guaranteed to refer to the same cell (i.e. I cannot store the ObjPtr value and use it, e.g., as a key somewhere).

Hence my question: How can I uniquely identify a cell in Excel in a way that survives renaming, cutting, and/or pasting cells in the Worksheet?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-10T16:46:00+00:00Added an answer on June 10, 2026 at 4:46 pm

    A pointer is created each time a variable is assigned hence you get different references unless you assign one variable to another in which case it is the same pointer and has the same reference. Unless you use a Static declaration the reference will usually change each time you run the sub procedure. If you declare the pointer as Static and assign it once it should maintain a constant reference each time the code is run even if a user moves the cell. I ran this code to test it and it seems to work.

        Sub TestCellIdentityModified()
    
        Dim rng1 As Range
        Dim rng2 As Range
        Static rngStatic As Range
    
        ' assign cell to pointer
        Set rng1 = ActiveSheet.Cells(2, 4)
        Debug.Print "rng1 = " & ObjPtr(rng1)
    
        ' assign same cell to a different pointer
        Set rng2 = ActiveSheet.Cells(2, 4)
        Debug.Print "rng2 = " & ObjPtr(rng2); ""
    
        ' assign one pointer to another
        Set rng2 = rng1
        Debug.Print "rng2 reassigned as rng1 pointer = " & ObjPtr(rng2)
    
        ' one time assignment of the same cell to a static pointer
        If rngStatic Is Nothing Then Set rngStatic = ActiveSheet.Cells(2, 4)
        Debug.Print "rngStatic = " & ObjPtr(rngStatic)
    
        Debug.Print " "
    
    End Sub
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

This question is related somewhat to the one i asked HERE . Now, i
Somewhat related to this question , but in the absence of any answer about
My question is somewhat related to this one: How does a generic constraint prevent
My question is somewhat related to this one: Explicitly implemented interface and generic constraint
This question is related to that one. But somewhat extended. Let's assume we have
This is somewhat related to this question , but I was hoping there may
So this question is (somewhat distantly) related to this previous question: Best way to
I know that there are a lot of questions somewhat related to this one,
This is somewhat related to the question posed in this question but I'm trying
My last question was somewhat narrower than this one. I am interested to know

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.