Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.worksheet.functions
external usenet poster
 
Posts: 13
Default Generating an auto number

How can I generate an auto number in cell A1 by simply clicking on cell B1
  #2   Report Post  
Posted to microsoft.public.excel.worksheet.functions
external usenet poster
 
Posts: 2,203
Default Generating an auto number

I can think of 2 ways to do it quickly in VB code attached to the worksheet
itself.

I am thinking this would be the more certain, less prone to accident way:

Private Sub Worksheet_BeforeDoubleClick(ByVal Target As Range, _
Cancel As Boolean)
Dim iSect As Range
'did you double-click in cell B1?
Set iSect = Application.Intersect(Range(Target.Address), Range("B1"))
If iSect Is Nothing Then
' no, you did not
Exit Sub
End If
'yes, you did, increment contents of A1 by 1
Application.EnableEvents = False
Range("A1") = Range("A1") + 1
Cancel = True ' negate the double-click action
Application.EnableEvents = True
End Sub

That will increment the contents of A1 by 1 each time you double-click in
cell B1.

The other way is to literally increment A1 by 1 every time you go to cell B1
(but not each time you click it - just when you choose it after some other
cell on the sheet has been previously selected).

Private Sub Worksheet_SelectionChange(ByVal Target As Range)
Dim iSect As Range
'did you select cell B1?
Set iSect = Application.Intersect(Range(Target.Address), Range("B1"))
If iSect Is Nothing Then
' no, you did not
Exit Sub
End If
'yes, you did, increment contents of A1 by 1
Application.EnableEvents = False
Range("A1") = Range("A1") + 1
Application.EnableEvents = True
End Sub

Use one or the other of these, not both. If you need help getting the code
into the Worksheet code module, easy way is to right-click on the sheet's tab
and choose [View Code]. For more help, see
http://www.jlathamsite.com/Teach/WorksheetCode.htm


"JohannM" wrote:

How can I generate an auto number in cell A1 by simply clicking on cell B1

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
Generate Auto Order Number cher Excel Discussion (Misc queries) 1 March 28th 06 06:15 PM
auto move cursor after entering number in excel Mike C Excel Worksheet Functions 3 January 2nd 06 03:27 AM
how to auto increment a number each time i open the worksheet fred rondak Excel Worksheet Functions 1 June 25th 05 11:40 PM
How do I auto number cells in an Excel template? Natalie Excel Discussion (Misc queries) 3 March 30th 05 03:42 AM
assign auto number and auto date Krit Kasem Excel Discussion (Misc queries) 2 January 14th 05 02:55 AM


All times are GMT +1. The time now is 07:17 PM.

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

About Us

"It's about Microsoft Excel"