Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 102
Default Worksheet_change error

Hi All
I have a great code that replaces characters with symbols - and it works
brilliantly, until I select multiple cells on the worksheet and hit the
delete key.
I then get a "Run-time error '13': Type mismatch" error message.
Can someone tell me what I need to add to this code to stop the error if a
user hits the delete key?

Private Sub Worksheet_Change(ByVal Target As Range)
Set r = Target
Dim s As String
s = r.Value
s = Replace(s, "[", ChrW(780))
s = Replace(s, "]", ChrW(768))
s = Replace(s, "<", ChrW(772))
s = Replace(s, "", ChrW(769))
s = Replace(s, "~", ChrW(776))
Application.EnableEvents = False
r.Value = s
Application.EnableEvents = True
End Sub
--
Thank for your help
BeSmart
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,501
Default Worksheet_change error

Try:-

Private Sub Worksheet_Change(ByVal target As Range)
Application.EnableEvents = False
Dim s As String
Set myRange = target
For Each r In myRange
s = r.Value
s = Replace(s, "[", ChrW(780))
s = Replace(s, "]", ChrW(768))
s = Replace(s, "<", ChrW(772))
s = Replace(s, "", ChrW(769))
s = Replace(s, "~", ChrW(776))
r.Value = s
Next
Application.EnableEvents = True
End Sub

Mike


"BeSmart" wrote:

Hi All
I have a great code that replaces characters with symbols - and it works
brilliantly, until I select multiple cells on the worksheet and hit the
delete key.
I then get a "Run-time error '13': Type mismatch" error message.
Can someone tell me what I need to add to this code to stop the error if a
user hits the delete key?

Private Sub Worksheet_Change(ByVal Target As Range)
Set r = Target
Dim s As String
s = r.Value
s = Replace(s, "[", ChrW(780))
s = Replace(s, "]", ChrW(768))
s = Replace(s, "<", ChrW(772))
s = Replace(s, "", ChrW(769))
s = Replace(s, "~", ChrW(776))
Application.EnableEvents = False
r.Value = s
Application.EnableEvents = True
End Sub
--
Thank for your help
BeSmart

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 102
Default Worksheet_change error

Fantastic - thanks heaps Mike!!!!
--
BeSmart


"Mike H" wrote:

Try:-

Private Sub Worksheet_Change(ByVal target As Range)
Application.EnableEvents = False
Dim s As String
Set myRange = target
For Each r In myRange
s = r.Value
s = Replace(s, "[", ChrW(780))
s = Replace(s, "]", ChrW(768))
s = Replace(s, "<", ChrW(772))
s = Replace(s, "", ChrW(769))
s = Replace(s, "~", ChrW(776))
r.Value = s
Next
Application.EnableEvents = True
End Sub

Mike


"BeSmart" wrote:

Hi All
I have a great code that replaces characters with symbols - and it works
brilliantly, until I select multiple cells on the worksheet and hit the
delete key.
I then get a "Run-time error '13': Type mismatch" error message.
Can someone tell me what I need to add to this code to stop the error if a
user hits the delete key?

Private Sub Worksheet_Change(ByVal Target As Range)
Set r = Target
Dim s As String
s = r.Value
s = Replace(s, "[", ChrW(780))
s = Replace(s, "]", ChrW(768))
s = Replace(s, "<", ChrW(772))
s = Replace(s, "", ChrW(769))
s = Replace(s, "~", ChrW(776))
Application.EnableEvents = False
r.Value = s
Application.EnableEvents = True
End Sub
--
Thank for your help
BeSmart

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
Worksheet_change event handler error gen Excel Discussion (Misc queries) 0 January 18th 08 04:55 AM
Compile error: Ambigious name detected: Worksheet_Change **NEWBIE** Dan Excel Programming 3 May 26th 06 05:57 PM
Prevent error when deleting row within Worksheet_Change target ran Peter Rooney Excel Programming 0 February 1st 06 03:41 PM
Error with Target.Name.Name in Worksheet_Change event SuperJas Excel Programming 2 January 8th 04 03:26 AM
Delete key causes error in Worksheet_Change in 2003 Don Excel Programming 1 December 14th 03 10:05 PM


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