Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 389
Default Worksheet_Change code problem

The goal is to keep a user from pasting to more than one cell at a time.

This is on the Worksheet_Change of a Sheet:

If Target.Cells.Count 1 Then
Selection.ClearContents
End If

I want to put a MsgBox to tell the user why the selection was cleared and
they can only paste to one cell at a time. But when I but a MsgBox after the
Selection.ClearContents it goes into a loop and the MsgBox will not close.

How do I correct this.

Thank you for your help.

Steven
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35,218
Default Worksheet_Change code problem

Tell excel not to look for changes while your code is making a change:

if target.cells.count 1 then
application.enableevents = false
target.clearcontents
application.enableevents = true
end if

===
Although, you may want to try:

if target.cells.count 1 then
with application
.enableevents = false
.undo 'put things back the way they were, don't just clear
.enableevents = true
end with
end if



Steven wrote:

The goal is to keep a user from pasting to more than one cell at a time.

This is on the Worksheet_Change of a Sheet:

If Target.Cells.Count 1 Then
Selection.ClearContents
End If

I want to put a MsgBox to tell the user why the selection was cleared and
they can only paste to one cell at a time. But when I but a MsgBox after the
Selection.ClearContents it goes into a loop and the MsgBox will not close.

How do I correct this.

Thank you for your help.

Steven


--

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
need help with Worksheet_Change code Alex Excel Programming 6 August 14th 06 08:38 PM
need help creating a Worksheet_Change code Cajun20th Excel Worksheet Functions 4 May 18th 06 09:12 AM
inserting code into a Worksheet_Change event Bri[_3_] Excel Programming 3 May 4th 06 09:04 PM
disappearing worksheet_change VBA code - help! [email protected] Excel Programming 1 December 11th 05 07:20 AM
Worksheet_Change even code will not run retseort[_13_] Excel Programming 3 November 28th 05 10:35 PM


All times are GMT +1. The time now is 03:04 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"