2
나는 세 가지 시트 (내가 하나를 시작 해요)을 순환에 좋아 채우는 자동으로 열 C의 특정 유형을 찾아서 것/열 D의 In-cell 드롭 다운 (데이터 유효성 검사 설정에서 발견 된 것과 유사)을 자동 채우기. In-cell 드롭 다운에는 모든 유형의 값이 나열되어야하지만 유형에 속한 값으로 자동 채취해야합니다.
문제 코드는 아래와 같은 값으로 모든 셀 내 드롭 다운 목록을 채워
즉 타입 1의 항목 1 - 항목 2 - 항목 3 - Item4.
모든 값을 나열하는 동시에 셀을 자동 채우는 방법을 모르겠습니다.
간단하게하기 위해서
코드
원하는 출력, 난 단지 아래의 코드에서 처음 두 유형을 추가했습니다.
Sub AutoDropdown()
Dim PersonSource As Range
Dim PersonSourceTotal As Range
Dim PersonCell As Range
'Dim ws As Worksheet
Dim i As Integer
Dim lastRow As Integer
Set PersonSourceTotal = Sheets("Sheet1").Range("D2:D200")
With PersonSourceTotal.Offset(0, -2)
lastRow = .Cells(.Rows.Count, PersonSourceTotal.Columns.Count).End(xlUp).Row
End With
Set PersonSource = Sheets("sheet1").Range("D2:D" & lastRow)
On Error Resume Next
For Each PersonCell In PersonSource
Name = PersonCell.Offset(0, -3)
ID = PersonCell.Offset(0, -2)
If Name <> "" And ID <> "" Then
For i = 0 To lastRow
If PersonCell.Offset(i, -1) = "Type1" Then
arr1 = Array("Item1", "Item2", "Item3", "Item4")
arr1Merged = Join(arr1, "--")
With PersonCell.Validation
.Delete
.Add Type:=xlValidateList, AlertStyle:=xlValidAlertStop, _
Operator:=xlBetween, Formula1:=arr1Merged
.IgnoreBlank = True
.InCellDropdown = True
.InputTitle = ""
.ErrorTitle = ""
.InputMessage = ""
.ErrorMessage = ""
.ShowInput = True
.ShowError = True
End With
ElseIf PersonCell.Offset(i, -1) = "Type2" Then
arr2 = Array("Item5", "Item6", "Item7", "Item8", "Item9")
arr2Merged = Join(arr2, "--")
Debug.Print (arr2Merged)
With PersonCell.Validation
.Delete
.Add Type:=xlValidateList, AlertStyle:=xlValidAlertStop, _
Operator:=xlBetween, Formula1:=arr2Merged
.IgnoreBlank = True
.InCellDropdown = True
.InputTitle = ""
.ErrorTitle = ""
.InputMessage = ""
.ErrorMessage = ""
.ShowInput = True
.ShowError = True
End With
End If
Next i
Else
MsgBox "Remember to add Name and ID"
End If
Next PersonCell
End Sub
Hey Xabier. 나는 diasgree :) 나는 단지 다시 확인을 테스트했습니다. 셀은 자동 채우기되지 않으며 Type1 (Item1 - Item2 - Item3 - Item4) 값만 나타납니다. – Saud
데이터 유효성 검사의 수식을 사용하여이 작업을 수행 할 수 있습니다. http://www.contextures.com/xlDataVal02.html 링크를 참조하십시오. 내가 수식을 제공 할 수있는 방법을 시도해보십시오. –
@Saud 내 대답을 업데이트했습니다. 의도 한대로 작동하면 알려주세요. – Xabier