only select one cell

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I need a macro that will prevent users from selecting more than one cell at a
time.
 
I need a macro that will prevent users from selecting more than one cell at a
time.

Not shure how you would accomplish this with a macro.. you could try a
BFH and some creative words.. Unless your user is a 5yr old.. they
should be able to select only ONE cell.. maby a 15min Training session
or something would work..
 
Well, I prefur safe to sorry. I'm running a macro and its tends to spaz if
you try to delete multiple cells at one time. Since I'm having trouble
getting to fix it I thought it might be simpler to just remove that ability.
 
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
On Error goto ErrHandler
Application.EnableEvents = False
Target(1).Select
SaveValue = Target(1).Value
ErrHandler:
Application.EnableEvents = True
End Sub
 
A couple of things... This code needs to be placed in the sheet itself (right
click the tab and select View Code and paste the code in the code window.)
The posted code will always select the upper left hand cell. If you would
prefer the following code will select the active cell which I found my users
prefered (personal preference). ***Note that this only makes a difference if
you have users that select ranges of cells right to left instead of left to
right.

Private Sub Worksheet_SelectionChange(ByVal Target As Range)
On Error GoTo ErrHandler
Application.EnableEvents = False
ActiveCell.Select
ErrHandler:
Application.EnableEvents = True
End Sub

Finally (and this is for Tom) what is the significance of your Variable
"SaveValue" which you don't use?
 
Hi Kiba ! :)
You need to write an event procedure as follows.

Private Sub Selection change()

If Instr(1,selection.address,":") > 0 then
Msgbox "Selection not valid !!
Endif

End sub

This procedure displays an error message if a range larger than 1
cell is selected.

I hope you are able to adapt it ( use the idea ) for your specific
need.

Good luck !
 
Right click sheet tab>view code>insert this
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
If Target.Cells.Count > 1 Then Exit Sub
MsgBox "hi"
End Sub
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top