[英]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.