![]() |
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? |
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? |
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? |
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? |
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? |
All times are GMT +1. The time now is 09:13 AM. |
Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com