Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Junior Member
 
Posts: 12
Default Preventing Multi Cell Selection

I have built macros which are activated by a single cell selection in a worksheet (using a change event macro). I get an error if the user inadvertently selects more than one cell. My questions a

1. How can I prevent the user from selecting more than one cell on a particular worksheet?

2. What code will abort a macro if there is an error.

Many Thanks

Michael
  #2   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 35,218
Default Preventing Multi Cell Selection

#1. I like to start my worksheet_change procedures with code like:

if target.cells.count 1 then exit sub
if intersect(target, me.range("a1:c9")) is nothing then exit sub

Only one cell in the Range of A1:C9.

#2. You could use the worksheet_selectionchange event.

Option Explicit
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
If Target.Cells.Count 1 Then
Application.EnableEvents = False
Target.Cells(1).Select
Application.EnableEvents = True
End If
End Sub

Michael Excel Dude wrote:

I have built macros which are activated by a single cell selection in a
worksheet (using a change event macro). I get an error if the user
inadvertently selects more than one cell. My questions a

1. How can I prevent the user from selecting more than one cell on a
particular worksheet?

2. What code will abort a macro if there is an error.

Many Thanks

Michael

--
Michael Excel Dude


--

Dave Peterson
  #3   Report Post  
Junior Member
 
Posts: 12
Default

Dave, as always, you advice is flawless. Thanks very much.

----------------------------

Quote:
Originally Posted by Dave Peterson
#1. I like to start my worksheet_change procedures with code like:

if target.cells.count 1 then exit sub
if intersect(target, me.range("a1:c9")) is nothing then exit sub

Only one cell in the Range of A1:C9.

#2. You could use the worksheet_selectionchange event.

Option Explicit
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
If Target.Cells.Count 1 Then
Application.EnableEvents = False
Target.Cells(1).Select
Application.EnableEvents = True
End If
End Sub

Michael Excel Dude wrote:

I have built macros which are activated by a single cell selection in a
worksheet (using a change event macro). I get an error if the user
inadvertently selects more than one cell. My questions a

1. How can I prevent the user from selecting more than one cell on a
particular worksheet?

2. What code will abort a macro if there is an error.

Many Thanks

Michael

--
Michael Excel Dude


--

Dave Peterson
Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
insert date Larry Excel Worksheet Functions 28 July 15th 06 02:41 AM
?IF function for preventing a cell being filled by formula confused teacher Excel Worksheet Functions 3 July 6th 06 06:01 AM
Line selection from a cell script through a VBA macro CamiIRE Setting up and Configuration of Excel 2 April 11th 06 04:28 PM
cell color index comparison MINAL ZUNKE New Users to Excel 1 June 30th 05 07:11 AM
Arrows move worksheet rather than cell selection, how fix? grenada49 Excel Worksheet Functions 3 May 17th 05 09:05 PM


All times are GMT +1. The time now is 04:35 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"