안녕하십니까. 내가 만든 목록에서 셀에 정확히 동일한 데이터를 입력 할 수있는 코드를 작성하는 방법을 알아 내려고 노력하고 있습니다. 코드에서 사용자 항목의 유효성을 검사하고 항목이 목록에 있는지 확인하고 사용자가 입력 한 데이터를 지우지 않고 메시지를 제공하는지 확인합니다. 나는 거의 다 왔지만 Vlook 작업을하지 않는 것 같습니다. 어떤 도움이라도 대단히 감사 할 것입니다. 아래에있는 코드는 내가 작성한 코드입니다.사용자가 잘못된 데이터를 셀에 입력하지 못하도록하는 VBA 코드 Excel
Option Explicit
Private Sub Worksheet_Change(ByVal Target As Excel.Range)
Dim rng As Range
Dim aCell As Range
Dim LU As Range
Dim Celda As Range
'
On Error GoTo Whoa
Application.EnableEvents = False
'~~> This is the range of cells where I want the user to input the data
Set rng = Range("A1:A15")
'THis is the range where I want the macro to look if the data the user entered is in the list
Set LU = Application.WorksheetFunction.VLookup(aCell.Value, Range("F1:F5"), 1, False)
On Error GoTo MyErrorHandler:
If Not Application.Intersect(Target, rng) Is Nothing Then
'~~> Loop through all cells in the range
For Each aCell In rng
If aCell.Value <> "" Then
If aCell.Value <> LU Then
aCell.ClearContents
MyErrorHandler:
If Err.Number = 1004 Then
aCell.ClearContents
MsgBox "Item Number es Incorrecto - Error en la celda " & aCell.Address
End If
End If
End If
Next
End If
Letscontinue:
Application.EnableEvents = True
Exit Sub
Whoa:
MsgBox Err.Description
Resume Letscontinue
End Sub
데이터 유효성 검사에서 VBA를 정확하게 사용하는 이유는 무엇입니까? – nbayly
유효성 검사 목록을 사용하지 않는 이유는 무엇입니까? http://www.contextures.com/xlDataVal01.html – RCaetano
@nbayly 15 초 빠르게 xD – RCaetano