이 코드는 귀하의 제안을 해결합니다.
Private Sub UserForm_Initialize()
Dim RowMax As Integer
Dim wsh As Worksheet
Dim countExit As Integer
Dim CellCombo1 As String
Dim i As Integer
Dim j As Integer
Set wsh = ThisWorkbook.Sheets("Sheet2")
RowMax = wsh.Cells(Rows.Count, "A").End(xlUp).Row
'find last row of sheet in column A
ComboBox1.Clear
'clear all value of comboBox1
With ComboBox1
For i = 2 To RowMax
'Run each row of column A
countExit = 0
CellCombo1 = wsh.Cells(i, "A").Value
For j = i To 2 Step -1
'just show value not duplicate
If CellCombo1 = wsh.Cells(j, "A").Value Then
countExit = countExit + 1
End If
Next j
If countExit = 0 Then
ElseIf countExit > 1 Then
Else
.AddItem CellCombo1
End If
Next i
End With
End Sub
Private Sub ComboBox1_Change()
Dim RowMax As Integer
Dim wsh As Worksheet
Dim countExit As Integer
Dim CellCombo2 As String
Dim i As Integer
Set wsh = ThisWorkbook.Sheets("Sheet2")
RowMax = wsh.Cells(Rows.Count, "A").End(xlUp).Row
'find last row of sheet in column A
ComboBox2.Clear
'clear all value of comboBox2
With ComboBox2
For i = 2 To RowMax
If wsh.Cells(i, "A").Value = ComboBox1.Text Then
'Just show value of mapping with column A
.AddItem wsh.Cells(i, "B").Value
Else
End If
Next i
End With
End Sub
위에서 언급 한 문제는 새로운 비즈니스와 개인이 해당 비즈니스에 연결된 상태에서 지속적으로 추가된다는 것입니다. 내가 자동으로 선택할 수있는 콤보 상자가 필요합니다, 항목 수가 고정되어 있지 않습니다 –
@benjaminsolanke 그냥'ComboBox2.Clear' 라인을 추가하십시오. 무료로 당신을 도우려는 사람들과 잘 지내십시오. –
@ AK47 요청한 사람이 자신의 코드를 개발하려는 노력을하지 않는다면 코드를 제공해서는 안됩니다. –