我最初是在link处找到此代码的,它很好用。呼叫功能在单元格G56中。我想向其添加另一个级别,并根据验证结果为true / false使其以绿色或红色突出显示合并的单元格(“ B56:F56”)。
我想问问OP他们是否有解决方案,但该网站不允许我这样做。 我还尝试将条件格式设置为正确/错误的单元格以更改颜色,但这种方法不起作用。
这在模块1中
Function ValidateEmail(emailAddr As String) As Boolean
Dim findAt As Long
Dim findLastDot As Long
Dim findSpace As Long
' Default validate is true
ValidateEmail = True
'<<tried adding then range color selection here no luck
findAt = InStr(emailAddr, "@")
findLastDot = InStrRev(emailAddr, ".")
findSpace = InStr(emailAddr, " ")
' Check for characters
If (findAt = 0) Or (findLastDot = 0) Or (findSpace > 0) Then
ValidateEmail = False
Exit Function
End If
' Make sure amperand not first space
If findAt = 1 Then
ValidateEmail = False
Exit Function
End If
' Make sure the last dot comes at least two spots after the ampersand
If (findLastDot - 1) <= findAt Then
ValidateEmail = False
Exit Function
End If
End Function