[英]CircleInvalid and ClearCircle methods for a particular cell in excel vba 2007
我正在Excel 2007中使用数据验证。我正在使用此代码制作带有红色圆圈的无效数据。
Private Sub Worksheet_Change(ByVal Target As Range)
Dim rc As Integer
Range(Target.Address).Select
ActiveSheet.ClearCircles
ActiveSheet.CircleInvalid
If Not Range(Target.Address).Validation.Value Then
rc = MsgBox("Data Validation errors exist! " & Range
(Target.Address).Validation.ErrorMessage & " Please correct circled entries!", vbCritical, "Failure")
Exit Sub
End If
End Sub
正如您在代码中看到的那样,当我输入错误的数据时,将首先选择该特定范围,然后所有无效数据都用红色圆圈标记。
但我希望仅将特定单元格标记为红色,而不是所有数据。
谢谢。
您可以从Excel MVP尝试以下代码:
Dim TheCircledCell As Range
Sub CircleCells(CellToCircle As Range)
If Not CellToCircle Is Nothing Then
With CellToCircle
If .Count > 1 Then Exit Sub
Set TheCircledCell = CellToCircle
.Validation.Delete
.Validation.Add xlValidateTextLength, xlValidAlertInformation, xlEqual, 2147483647#
.Validation.IgnoreBlank = False
.Parent.CircleInvalid
End With
End If
End Sub
Sub ClearCircles()
If Not TheCircledCell Is Nothing Then
With TheCircledCell
.Validation.Delete
.Parent.ClearCircles
End With
End If
End Sub
请注意,您不能在这些单元格上使用Excel标准验证功能。
[ 代码的来源和说明 ]
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.