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

  • Home
  • SEARCH
  • 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 254499
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T21:51:06+00:00 2026-05-11T21:51:06+00:00

I want to have/define a unique id for each data row in my Excel

  • 0

I want to have/define a unique id for each data row in my Excel data sheet – such that I can use it when passing the data onwards and it stays the same when rows are added/deleted above it.

My thoughts are to use the ID attribute of Range (msdn link)

So, I have a user defined function (UDF) which I place in each row that gets/sets the ID as follows:

Dim gNextUniqueId As Integer

Public Function rbGetId(ticker As String)
    On Error GoTo rbGetId_Error
    Dim currCell As Range
    'tried using Application.Caller direct, but gives same error
    Set currCell = Range(Application.Caller.Address)
    If currCell.id = "" Then
        gNextUniqueId = gNextUniqueId + 1
        'this line fails no matter what value I set it to.
        currCell.id = Str(gNextUniqueId)
    End If
    rbGetId = ticker & currCell.id
    Exit Function

    rbGetId_Error:
    rbGetId = "!ERROR:" & Err.Description
End Function

But this fails at the line mentioned with

“Application-defined or object-defined error”

I thought perhaps its one of those limitations of UDFs, but I also get the same error if I try it from code triggered from a ribbon button…

Any other suggestions on how to keep consistent ids – perhaps I should populate the cells via my ribbon button, finding cells without IDs and generating/setting the cell value of those…

EDIT:
As Ant thought, I have the sheet protected, but even in an unlocked cell it still fails. Unprotecting the sheet fixes the problem…. but I have used “Protect UserInterFaceOnly:=True” which should allow me to do this. If I manually allow “Edit Objects” when I protect the sheet it also works, but I don’t see a programmatic option for that – and I need to call the Protect function in AutoOpen to enable the UserInterfaceOnly feature…

I guess I need to turn off/on protect around my ID setting – assuming that can be done in a UDF… which it seems it cannot, as that does not work – neither ActiveSheet.unprotect nor ActiveWorkbook.unprotect 🙁

Thanks in advance.
Chris

  • 1 1 Answer
  • 1 View
  • 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-05-11T21:51:06+00:00Added an answer on May 11, 2026 at 9:51 pm

    I have found that if I protect the sheet with “Protect DrawingObjects:=False”, the UDF can set the Id. Strange.

    Thanks for all the help with this.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Alright, I have some data that I need to assign an int type identifier
I have daily records of production per category, i.e. category A: 80 tons. Each
I have a WinForm TreeView Control that displays the Parent Child relationship of CaseNotes(I
The problem I have is illustrated in the following code. #include <iostream> #define X
Assume that I have a table user_count defined as follows: id primary key, auto
i have a map system (grid) for my website. I have defined 40000 'fields'
Given a functor appropriate for use with std::for_each and friends: template <typename T> struct
I am struggling with the best way to handle a WPF application that has
I'm working on a project where I can generate Word documents, one of the
I'm trying to determine how I can detect when the user changes the Windows

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.