Format/Input question

  • Thread starter Thread starter Rick Price
  • Start date Start date
R

Rick Price

Is there away to have a checkbox in a cell so that all that can be
entered would be an X for nothing?
 
You could give the cell a custom format so that the cell displays an x no matter
what's typed in the cell--the cell will still contain whatever they type (as
seen in the formula bar), but it'll display an x.

Select the range
format|Cells|number tab|custom category
X;X;X;X

Another option would be to use a worksheet event that replaces anything with an
X.

If you want to try, right click on the worksheet tab that should have this
behavior and select view code. Then paste this into the newly opened
codewindow:

Option Explicit
Private Sub Worksheet_Change(ByVal Target As Range)
With Target
If .Cells.Count > 1 Then Exit Sub
If Intersect(.Cells, Me.Range("A:a")) Is Nothing Then Exit Sub

On Error GoTo ErrHandler:

If IsEmpty(.Value) Then Exit Sub

Application.EnableEvents = False
.Value = "X"
End With

ErrHandler:
Application.EnableEvents = True

End Sub

I used any cell in column A, but you can change the range to what you wanted.
 
Thanks


Dave said:
You could give the cell a custom format so that the cell displays an x no matter
what's typed in the cell--the cell will still contain whatever they type (as
seen in the formula bar), but it'll display an x.

Select the range
format|Cells|number tab|custom category
X;X;X;X

Another option would be to use a worksheet event that replaces anything with an
X.

If you want to try, right click on the worksheet tab that should have this
behavior and select view code. Then paste this into the newly opened
codewindow:

Option Explicit
Private Sub Worksheet_Change(ByVal Target As Range)
With Target
If .Cells.Count > 1 Then Exit Sub
If Intersect(.Cells, Me.Range("A:a")) Is Nothing Then Exit Sub

On Error GoTo ErrHandler:

If IsEmpty(.Value) Then Exit Sub

Application.EnableEvents = False
.Value = "X"
End With

ErrHandler:
Application.EnableEvents = True

End Sub

I used any cell in column A, but you can change the range to what you wanted.
 
Back
Top