Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Dingbat
 
Posts: n/a
Default automatically increment field by one

Hi all

I have an excel spreadsheet that contains a field that we at present
manually update and therefore have to keep checking the last sequence number
used.
I would like to somehow create a way to auto update the field so that when
opened the file will update the number (similar to purchase order
sequencing). The field will also need to be secure so that it cannot be over
written.

Any idea's ?
  #2   Report Post  
Nick Hodge
 
Posts: n/a
Default automatically increment field by one

You could do this with some code in the Workbook_Open event

For example

Private Sub Workbook_Open()
With Sheet1
.Unprotect Password:="ABCD"
.Range("A1").Value = .Range("A1").Value + 1
.Protect Password:="ABCD"
End With
End Sub

This will unlock a protected sheet with the codename of Sheet1 with a
password of ABCD then it increments the value of A1 on Sheet1 and locks it
down again. (You will need to unlock all cells to work with them when the
sheet is protected, leaving A1 the locked cell to protect from meddling
hands

If you need to know where the code goes see here and look for the
ThisWorkbook module.

http://www.nickhodge.co.uk/vba/vbaim....htm#eventcode

--
HTH
Nick Hodge
Microsoft MVP - Excel
Southampton, England
www.nickhodge.co.uk
HIS


"Dingbat" wrote in message
...
Hi all

I have an excel spreadsheet that contains a field that we at present
manually update and therefore have to keep checking the last sequence
number
used.
I would like to somehow create a way to auto update the field so that when
opened the file will update the number (similar to purchase order
sequencing). The field will also need to be secure so that it cannot be
over
written.

Any idea's ?



  #3   Report Post  
Bob Phillips
 
Posts: n/a
Default automatically increment field by one

Private Sub Workbook_Open()
With Worksheets("Sheet1").Range("A1")
.Value = .Value + 1
End With
End Sub

'This is workbook event code.
'To input this code, right click on the Excel icon on the worksheet
'(or next to the File menu if you maximise your workbooks),
'select View Code from the menu, and paste the code

--

HTH

RP
(remove nothere from the email address if mailing direct)


"Dingbat" wrote in message
...
Hi all

I have an excel spreadsheet that contains a field that we at present
manually update and therefore have to keep checking the last sequence

number
used.
I would like to somehow create a way to auto update the field so that when
opened the file will update the number (similar to purchase order
sequencing). The field will also need to be secure so that it cannot be

over
written.

Any idea's ?



Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

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


Similar Threads
Thread Thread Starter Forum Replies Last Post
How to fill the matched field automatically SJ Hong Excel Discussion (Misc queries) 2 October 20th 05 08:25 AM
How do I automatically increment worksheet number when pasting a . Mr Keldor Excel Worksheet Functions 1 April 21st 05 06:06 PM
Field whose value increments automatically Quinnboy Excel Discussion (Misc queries) 2 March 15th 05 04:27 PM
Method to increment value in data field? Karl H Excel Discussion (Misc queries) 1 December 4th 04 07:31 PM
Method to increment value in data field? Karl H Excel Discussion (Misc queries) 1 December 4th 04 05:25 PM


All times are GMT +1. The time now is 11:48 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"