logstarter
New Member
- Joined
- Apr 14, 2017
- Messages
- 39
I have written the following VBA. It works well when the input is within cell width. However, when the input is too long and exceeds the cell width (which some part of input will be hidden), the function seems not functioning properly.
if the input exceeds the cell width, Message Run 11 can be shown but Run 22 cannot. I have no idea why and would like to ask for help for this issue.
Thank you.
Code:
Sub Workbook_SheetChange(ByVal Sh As Object, ByVal Target As Range)
Dim ChangedRow As Integer
With Sh
If Not Intersect(Target, Sh.Range("E:E")) Is Nothing Then
On Error GoTo bm_Safe_Exit
Application.EnableEvents = False
ChangedRow = Target.Row
If WorksheetFunction.CountA(Target) > 0 Then
MsgBox "run 2"
If checkDuplicate(Target) = False Then
confirmChange = MsgBox("No duplicate", vbYesNo + vbQuestion)
Else
confirmChange = MsgBox("Duplicate", vbYesNo + vbQuestion)
End If
MsgBox "run 3"
If confirmChange = vbYes Then
UserForm1.Show
End If
End If
End If
End With
bm_Safe_Exit:
Application.EnableEvents = True
End Sub
Function checkDuplicate(ByVal ChangedCell As Range) As Boolean
ContactNo = ChangedCell.Value
Dim dupContactNo As Boolean
dupContactNo = False
MsgBox "run 11"
Set Rng = ActiveSheet.Cells.Find(What:=ContactNo, After:=ChangedCell, LookIn:=xlValues, LookAt:=xlWhole, SearchOrder:=xlByRows, SearchDirection:=xlNext, MatchCase:=False)
If Not Rng Is Nothing And Rng.Address <> ChangedCell.Address Then dupContactNo = True
MsgBox "run 22"
.......
End Function
if the input exceeds the cell width, Message Run 11 can be shown but Run 22 cannot. I have no idea why and would like to ask for help for this issue.
Thank you.
Last edited: