Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 10
Default How do you update a public constant

I need to update a public constant every time I add a sheet.

Is there a better alternative?
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 7,247
Default How do you update a public constant

Greg,

You can't change the value of a constant; that's why they're
called constants. Create a public variable in a regular code
module:

Public NumSheets As Long

Then in the ThisWorkbook code module

Private Sub Workbook_NewSheet(ByVal Sh As Object)
NumSheets = ThisWorkbook.Worksheets.Count
End Sub


--
Cordially,
Chip Pearson
Microsoft MVP - Excel
Pearson Software Consulting, LLC
www.cpearson.com


"Greg" wrote in message
om...
I need to update a public constant every time I add a sheet.

Is there a better alternative?



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default How do you update a public constant

Or just use

ThisWorkbook.Worksheets.Count

directly. Just a thought.

--
Regards,
Tom Ogilvy

"Chip Pearson" wrote in message
...
Greg,

You can't change the value of a constant; that's why they're
called constants. Create a public variable in a regular code
module:

Public NumSheets As Long

Then in the ThisWorkbook code module

Private Sub Workbook_NewSheet(ByVal Sh As Object)
NumSheets = ThisWorkbook.Worksheets.Count
End Sub


--
Cordially,
Chip Pearson
Microsoft MVP - Excel
Pearson Software Consulting, LLC
www.cpearson.com


"Greg" wrote in message
om...
I need to update a public constant every time I add a sheet.

Is there a better alternative?





  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 10
Default How do you update a public constant

"Chip Pearson" wrote in message ...
Greg,

You can't change the value of a constant; that's why they're
called constants. Create a public variable in a regular code
module:

Public NumSheets As Long

Then in the ThisWorkbook code module

Private Sub Workbook_NewSheet(ByVal Sh As Object)
NumSheets = ThisWorkbook.Worksheets.Count
End Sub


--
Cordially,
Chip Pearson
Microsoft MVP - Excel
Pearson Software Consulting, LLC
www.cpearson.com


"Greg" wrote in message
om...
I need to update a public constant every time I add a sheet.

Is there a better alternative?


Thanks Chip,

I am curious to know why the body of the code needs to be in the
ThisWorkbook code module. Chip, what other circumstances would this
be required, and why would it used in the ThisWorkbook code module?
  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default How do you update a public constant

See Chip Pearson's page on Events
http://www.cpearson.com/excel/events.htm

Basically the creation of a new sheet causes this procedure to run.
Workbook Level events are maintained in the ThisWorkbook module.

--
Regards,
Tom Ogilvy

"Greg" wrote in message
om...
"Chip Pearson" wrote in message

...
Greg,

You can't change the value of a constant; that's why they're
called constants. Create a public variable in a regular code
module:

Public NumSheets As Long

Then in the ThisWorkbook code module

Private Sub Workbook_NewSheet(ByVal Sh As Object)
NumSheets = ThisWorkbook.Worksheets.Count
End Sub


--
Cordially,
Chip Pearson
Microsoft MVP - Excel
Pearson Software Consulting, LLC
www.cpearson.com


"Greg" wrote in message
om...
I need to update a public constant every time I add a sheet.

Is there a better alternative?


Thanks Chip,

I am curious to know why the body of the code needs to be in the
ThisWorkbook code module. Chip, what other circumstances would this
be required, and why would it used in the ThisWorkbook code module?



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
Constant loan payments vs. constant payments of principal lalli945 Excel Worksheet Functions 3 December 20th 06 10:33 PM
public sub Bob Excel Programming 3 December 10th 04 08:49 PM
Public constant in many workbooks MD Excel Programming 4 August 31st 04 10:41 PM
Public Sub Help No Name Excel Programming 2 May 18th 04 11:09 PM
A constant update Robert Couchman[_4_] Excel Programming 1 February 18th 04 01:57 PM


All times are GMT +1. The time now is 06:39 AM.

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"