Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Setting a Default Cell Value In Excel 97

Status
Not open for further replies.

rlpotty

Programmer
Feb 22, 2001
6
US
I'm trying to force a default value of 0.25 in cell D21 whenever someone opens Sheet1 in an Excel 97 workbook.

I tried to use the worksheet activate event:

Private Sub Worksheet_Activate()

Worksheets("Sheet1").Range("D21").Value = 0.25

End Sub

copying this code from the Microsoft Excel Language Reference, but the cell value doesn't change when I open the workbook. There is only one worksheet, Sheet1, in the workbook.

Any idea what I am doing wrong? Do I have to declare a workbook or worksheet object first?
 
Is the code in the WORKSHEET module or a standard module ??
Needs to be in the worksheet module
Other than that, it looks fine except that you do NOT need the sheet ref as it will be implied implicitly because that is the sheet that is now active Rgds
Geoff

Vah! Denuone Latine loquebar? Me ineptum. Interdum modo elabitur
 
I believe it's in the worksheet module. I right click on Sheet1(Sheet1) and select View Code.
 
OK - I think I know why it ain't working - If you only have one sheet, it is automatically active when the workbook is opened. Therefore, the worksheet_Activate event does NOT fire. Try putting it in the workbook_open event instead (you will need to include the sheet reference in this case)
Goto VBE
Doubleclick on Thisworkbook
Select "Workbook" fro0m left side drop down
The workbook_open event will be automatically generated
Enter
Worksheets("Sheet1").Range("D21").Value = 0.25

within there and all should be well (although wb_open events DON'T fire if the wb is opened thru code) Rgds
Geoff

Vah! Denuone Latine loquebar? Me ineptum. Interdum modo elabitur
 
It worked in both the workbook_activate and workbook_open events. I'll keep the multiple worksheet comment in mind when I have that situation.

Thanks for your help.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top