2011-11-17 3 views
0

Excel 2007에서 데이터 유효성 검사를 사용하고 있습니다.이 코드를 사용하여 잘못된 데이터를 빨간색 원으로 표시하려고합니다.Excel 2007의 특정 셀에 대한 CircleInvalid 및 ClearCircle 메서드

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 

내가 선택에 가고 다음 모든 잘못된 데이터가 빨간색 동그라미로 표시되어 특정 범위를 먼저 잘못된 데이터를 입력 할 때 코드에서 볼 수 있듯이.
하지만 그 특정 세포에만 빨간색으로 표시해야합니다 모든 데이터가 아닙니다.

감사합니다.

답변

1

당신은 엑셀 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 

참고.

[Source and explanation of the code]

관련 문제