2007年4月29日 星期日

[心得]-Execl Micro:檢測之前是否重複輸入字串

此巨集用以檢測目前輸入的字串,是否在之前已經輸入過了。例如在建立人名時~
Private Sub Worksheet_Change(ByVal Target As Range)
Keyin_words = Target.Text
Active_row = Target.Row
'字串檢查
If Not Len(Keyin_words) Then
If Chr_Num_check(Keyin_words) Then
If Not Cells.Find(Keyin_words, ActiveCell, xlValues, xlWhole, xlByRows, xlNext, False).Row = Active_row Then MsgBox ("前面有了")
Else
Exit Sub
End If
End If
End Sub

Function Chr_Num_check(str1) As Boolean
Chr_Num_check = False
For i = 1 To Len(str1)
str2 = Mid(str1, i, 1)
If Asc(str2) < 47 Or Asc(str2) > 58 Then
Chr_Num_check = True
Exit Function
End If
Next
End Function

沒有留言: