Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 2
Default Macro for a "counter"

I have an Excel 2007 spreadsheet that has an index number in cell AJ1. At
this time, the number is "40606" Each time the spreadsheet is opened, I
need the number to increase by 1. So that the next time the sheet is opened,
the index number would be "40607" and so on. Any help would be greatly
appreciated.
--
Lineman
  #2   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 35,218
Default Macro for a "counter"

If a user opens the workbook and closes without saving, does the cell get
incremented?

If yes, you'll want to save as soon as the cell is updated.

This code (with hardly any validity checks) would go in a General module:

Option Explicit
Sub auto_open()
Dim myCell As Range
With ThisWorkbook
Set myCell = .Worksheets("Sheetnamehere!").Range("AJ1")
End With

With myCell
If IsNumeric(.Value) Then
.Value = .Value + 1
Else
'what should happen? reset the counter?
.Value = 1
End If
End With

ThisWorkbook.Save 'save right away????

End Sub

If you're new to macros:

Debra Dalgleish has some notes how to implement macros he
http://www.contextures.com/xlvba01.html

David McRitchie has an intro to macros:
http://www.mvps.org/dmcritchie/excel/getstarted.htm

Ron de Bruin's intro to macros:
http://www.rondebruin.nl/code.htm

(General, Regular and Standard modules all describe the same thing.)

Lineman116 wrote:

I have an Excel 2007 spreadsheet that has an index number in cell AJ1. At
this time, the number is "40606" Each time the spreadsheet is opened, I
need the number to increase by 1. So that the next time the sheet is opened,
the index number would be "40607" and so on. Any help would be greatly
appreciated.
--
Lineman


--

Dave Peterson
  #3   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 2
Default Macro for a "counter"

Additional info that should have been included in my first posting. My bad.
Following is the macro that was used in Excel 2003. It does not work after
being copied into the 2007 Excel file. I changed the specified cell
information as the new (2007) sheet changed.

Sub Workbook_Open()
Sheets("Sheet1").Range("K1") = _
Sheets("Sheet1").Range("K1").Value + 1
End Sub

Would it be a version conflict that is causing this macro to not work in
Excel 2007?
--
Lineman


"Lineman116" wrote:

I have an Excel 2007 spreadsheet that has an index number in cell AJ1. At
this time, the number is "40606" Each time the spreadsheet is opened, I
need the number to increase by 1. So that the next time the sheet is opened,
the index number would be "40607" and so on. Any help would be greatly
appreciated.
--
Lineman

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
Excel - Golf - how to display "-2" as "2 Under" or "4"as "+4" or "4 Over" in a calculation cell Steve Kay Excel Discussion (Misc queries) 2 August 8th 08 01:54 AM
How do I set up a "roll over" counter in excel 2003? mcorson Excel Worksheet Functions 1 March 6th 07 09:10 PM
multiple file uploading - runtime error'13': type mismatch "While Counter <= UBound(FName)" Sinner Excel Discussion (Misc queries) 3 March 1st 07 09:44 AM
Need help with "Headline Counter" spreadsheet... Cloy Excel Discussion (Misc queries) 1 November 21st 06 10:04 AM
Macro to concatenate into "B1" B2 thru B"x" based on new data in "Col A" Dennis Excel Discussion (Misc queries) 0 July 17th 06 02:38 PM


All times are GMT +1. The time now is 04:07 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"