View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.newusers
Rick Rothstein Rick Rothstein is offline
external usenet poster
 
Posts: 5,934
Default assign a value to a cell

Yes, using VB code; however, it is unclear what you want to do if the user
tries to delete the value. The following code assume the user cannot delete
the value...

Right click the tab at the bottom of the worksheet, select View Code, and
copy/paste the following code into the code window that appeared...

' ************* Start of Code *************
Private Sub Worksheet_Change(ByVal Target As Range)
Const RangeAddress As String = "B3:C5"
If Not Intersect(Target, Range(RangeAddress)) Is Nothing Then
Application.EnableEvents = False
Target.Value = 1
Application.EnableEvents = True
End If
End Sub
' ************* End of Code *************

Note: Change the range in the first statement (starts with Const) to the
actual range you want to apply this functionality to.

If you want to allow the user to be able to delete the entry, use this code
instead...

' ************* Start of Code *************
Private Sub Worksheet_Change(ByVal Target As Range)
Const RangeAddress As String = "B3:C5"
If Not Intersect(Target, Range(RangeAddress)) Is Nothing Then
Application.EnableEvents = False
If Target.Value < "" Then Target.Value = 1
Application.EnableEvents = True
End If
End Sub
' ************* End of Code *************

--
Rick (MVP - Excel)


"totally lost" <totally wrote in message
...
is it possible to assign a cell or range of cells to have a value of 1 no
matter what you type into that cell