PC Review


Reply
Thread Tools Rate Thread

How can I define my own Primary Key in Excel?

 
 
auntiechrissie
Guest
Posts: n/a
 
      26th Nov 2009
I know that Excel uses the cell reference as a unique identifier, but can I
define my own "Primary Key" to ensure the uniqueness of a particular field
(for example, National Insurance Number)? I know that I could do this easily
in Access, but the rest of my task is so simple, using Access seems rather
like using a sledgehammer to crack a nut!

Many thanks
 
Reply With Quote
 
 
 
 
JLGWhiz
Guest
Posts: n/a
 
      26th Nov 2009
You can name the cell:

Select the cell and on the Excel menu bar - Insert>Nane>Define then enter
the name you want to use and click Add>OK. You can now refer to that name
in formulas and in code to identify that specific cell. See Excel help
files for details of using named ranges.

In VBA you can Use an Object Variable, to do the same thing.

Set myRange = ActiveSheet.Range("A1")

This will allow you to use myRange in code any time you want to refer to
Range("A1").
See VBA help files for details of using Object Variables.


"auntiechrissie" <(E-Mail Removed)> wrote in message
news:6F484BA1-1859-4FDE-AEFF-(E-Mail Removed)...
>I know that Excel uses the cell reference as a unique identifier, but can I
> define my own "Primary Key" to ensure the uniqueness of a particular field
> (for example, National Insurance Number)? I know that I could do this
> easily
> in Access, but the rest of my task is so simple, using Access seems rather
> like using a sledgehammer to crack a nut!
>
> Many thanks



 
Reply With Quote
 
JLatham
Guest
Posts: n/a
 
      26th Nov 2009
You can simulate the "autonumber" feature from Access with a couple of
methods proposed by J.E. McGimpsey that are documented here:

http://www.mcgimpsey.com/excel/udfs/sequentialnums.html

hopefully that'll help you with the issue.

"auntiechrissie" wrote:

> I know that Excel uses the cell reference as a unique identifier, but can I
> define my own "Primary Key" to ensure the uniqueness of a particular field
> (for example, National Insurance Number)? I know that I could do this easily
> in Access, but the rest of my task is so simple, using Access seems rather
> like using a sledgehammer to crack a nut!
>
> Many thanks

 
Reply With Quote
 
JLatham
Guest
Posts: n/a
 
      26th Nov 2009
On second thought, it might not be so complex as to require a McGimpsey
solution. Let's say that your key column will be column C and that C1 has a
label (as "National Insurance Number") in it and your data entries start on
row 2, then in cell C2 put this formula:
=MAX(C$1:C1)+1
which should return 1. Fill that formula on down the sheet and the number
will auto increment.

If you need to start with a 'seed' value, then make C2's formula something
like
=MAX(C$1:C1)+1+9944
where 9944 is your 'seed' value. Then in C3 you put the formula:
=MAX(C$1:C2)+1
and fill that on down the sheet.

You can modify that formula to add other things to the number, such as text,
or to format the result to a specific # of digits, as (in C2)
=TEXT(ROW()-ROW(C$1)+9944,"000000")
to get 6-digits displayed and fill that formula on down the sheet to
increment the value displayed.

or get really creative with something like this in C2
="NINABC-22-" & TEXT(ROW()-ROW(C$1)+9944,"000000")
which will display NINABC-22-009945 in the cell.

--Trying to post for 2nd time.

"auntiechrissie" wrote:

> I know that Excel uses the cell reference as a unique identifier, but can I
> define my own "Primary Key" to ensure the uniqueness of a particular field
> (for example, National Insurance Number)? I know that I could do this easily
> in Access, but the rest of my task is so simple, using Access seems rather
> like using a sledgehammer to crack a nut!
>
> Many thanks

 
Reply With Quote
 
JLGWhiz
Guest
Posts: n/a
 
      26th Nov 2009
In the VBA help files under both Primary Property and Unique Property, there
are code samples along with descriptive narrative that might be what you are
looking for. It apparently involves DAO and tables, but it sounds like what
you want.


"auntiechrissie" <(E-Mail Removed)> wrote in message
news:6F484BA1-1859-4FDE-AEFF-(E-Mail Removed)...
>I know that Excel uses the cell reference as a unique identifier, but can I
> define my own "Primary Key" to ensure the uniqueness of a particular field
> (for example, National Insurance Number)? I know that I could do this
> easily
> in Access, but the rest of my task is so simple, using Access seems rather
> like using a sledgehammer to crack a nut!
>
> Many thanks



 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Define a primary key during table generation Eric Lachowitz Microsoft Access Database Table Design 8 16th Oct 2006 09:26 PM
how to define a primary autonumbering field in a makequery =?Utf-8?B?UnVieQ==?= Microsoft Access Queries 9 1st May 2006 08:36 PM
Using SQL or Queries to define a primary key =?Utf-8?B?SmVyZW15?= Microsoft Access 1 13th Jul 2005 08:29 PM
How to define primary key in Master-Detail Table. Agnes Microsoft VB .NET 0 8th Dec 2004 03:38 PM
Two network Cards how to define the primary one ? Carlos Windows XP General 3 6th Mar 2004 04:20 AM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 02:46 PM.