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 bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Excel Default 1

Status
Not open for further replies.

ridge

Technical User
Jan 31, 2000
91
US
I have a spread sheet that will be used by several differant users. There is one cell that the user will have to enter a number... (1 thru 5).
I would like the cell to revert (Default) to a 5 each time the spread sheet is opened...Thus requiring the user to key in a 1, 2, 3, or 4 or leave as a 5.
 
On the workbooks Open event set whatever you wish to be defaulted right there.

To do this hit ALT+F11 to get to the VBE editor, from the VBAProject folders choose 'ThisWorkBook' and paste in this code changing your sheetname and Cell that you wish to default (this assumes A1).

Code:
Private Sub Workbook_Open()

With ThisWorkbook.Sheets("<Your Sheet Name Here>")
    .Range("A1").Value = 5
End With

End Sub

A,
 
Thank You...This is definately going in the right direction, however I am getting a error message.

runtime error '9':
subscript out of range.


My Workbook name is "Dozers"
My Sheetname is "450-G"
My cell to default to "5" is "M2"

Thanks for any more help.
 

Please post the code that is erroring.

Skip,

[glasses] [red]Be Advised![/red] Coeds studying ancient Egyptian plumbing, might be known as...
Pharaoh Faucet Majors [tongue]
 
Your code then should look like this

Code:
Private Sub Workbook_Open()

With ThisWorkbook.Sheets("450-G")
    .Range("M2").Value = 5
End With

End Sub
 
That works.... Thank You very much ! :)))))
 

Naturally, this literal code
Code:
With ThisWorkbook.Sheets("<Your Sheet Name Here>")
will fail, UNLESS you have a sheet named <Your Sheet Name Here>

Did you just copy 'n' paste 'n' RUN?


Skip,

[glasses] [red]Be Advised![/red] Coeds studying ancient Egyptian plumbing, might be known as...
Pharaoh Faucet Majors [tongue]
 
No...I changed the sheet names to correspond....I was doing something else wrong I suppose.... dont know what it was, but it works now...thanks
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top