LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 92
Default Paste Event Check

"Nathaniel W. Polky" wrote
: I have the following code that is intended to prevent the user from
entering
: certain characters. It works fine if the user goes cell by cell and
enters
: values. The problem occurs when the user copies values into a range of
: cells. Is there a way to work around this?
:
: Code:
:
: Private Sub Worksheet_Change(ByVal Target As Range)
: Dim blnIsOk As Boolean
:
: blnIsOk = True
: If Target.Column = 7 Then
: If InStr(1, Target.Value, """") Then
: blnIsOk = False
: ElseIf InStr(1, Target.Value, ",") Then
: blnIsOk = False
: ElseIf InStr(1, Target.Value, "&") Then
: blnIsOk = False
: End If
: End If
:
: If Not blnIsOk Then
: MsgBox "Commas, double quotes, and ampersands (the & symbol) are
not
: allowed in product descriptions. Please refer to the Product Description
: Policy. Thank You."
: Application.Undo
: End If
:
: End Sub


You need to wrap the target check in a for loop, something like this

blnIsOk = True
For Each c In Target
If c.Column = 7 Then
If InStr(1, c.Value, """") + _
InStr(1, c.Value, ",") + _
InStr(1, c.Value, "&") 0 Then
blnIsOk = False
End If
End If
Next c

If Not blnIsOk Then...

Paul D


 
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
how do I create event-activated macros that check every cell? JLC Excel Programming 4 November 29th 05 05:08 PM
Check File Name before Save Event ExcelMonkey[_170_] Excel Programming 0 September 29th 04 09:15 AM
Check File Name before Save Event ExcelMonkey[_169_] Excel Programming 1 September 29th 04 01:46 AM
check folder event Mark[_17_] Excel Programming 6 June 18th 04 03:08 PM
Change Event.....Spell Check CLR Excel Programming 7 February 1st 04 05:05 PM


All times are GMT +1. The time now is 05:10 AM.

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"