Home |
Search |
Today's Posts |
|
#1
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
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
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
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
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
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 |
Display Modes | |
|
|
![]() |
||||
Thread | Forum | |||
Worksheet_change event handler error | Excel Discussion (Misc queries) | |||
Compile error: Ambigious name detected: Worksheet_Change **NEWBIE** | Excel Programming | |||
Prevent error when deleting row within Worksheet_Change target ran | Excel Programming | |||
Error with Target.Name.Name in Worksheet_Change event | Excel Programming | |||
Delete key causes error in Worksheet_Change in 2003 | Excel Programming |