"combobox1"이라는 콤보 상자가있는 userform을 포함하는 통합 문서를 최근 작성했습니다.다른 통합 문서의 데이터를 아래 범위의 "B2 : B .."방향으로 가져 오는 코드가 있습니다. .. " 이제 콤보 상자에 견인 열을 넣는 방법을 만들고 싶습니다. 다른 열은 동일한 디렉토리에서 데이터를 가져 오지만 엑스의 범위는"A1 : A .... "입니다. 나는 당신의 도움이 필요합니다. thx .vba 외부 데이터를 사용하는 두 열 콤보 상자
[Private Sub UserForm_Initialize()
`Dim ListItems As Variant, i As Integer
`Dim SourceWB As Workbook
With Me.ComboBox1
.Clear ' remove existing entries from the listbox
' turn screen updating off,
' prevent the user from seeing the source workbook being opened
Application.ScreenUpdating = False
' open the source workbook as ReadOnly
Set SourceWB = Workbooks.Open("C:\Users\Mohsen\Desktop\new prj\Data base\partlist.xls", _
False, True)
ListItems = SourceWB.Worksheets(1).Range("B2:B1468").Value
' get the values you want
SourceWB.Close False ' close the source workbook without saving changes
Set SourceWB = Nothing
Application.ScreenUpdating = True
ListItems = Application.WorksheetFunction.Transpose(ListItems)
' convert values to a vertical array
For i = 1 To UBound(ListItems)
.AddItem ListItems(i) ' populate the listbox
Next i
.ListIndex = -1 ' no items selected, set to 0 to select the first item
End With
End Sub
답장을 보내 주셔서 감사합니다. 나는 "C9"범위에 콤보 상자 값을 연결하고 왼쪽 열 값을 C9로 반환하고 OK, 이제 두 번째 열 (오른쪽 하나)을 exp "B9"셀에 연결하려고합니다. 두 개의 연결 값을 설정하는 VBA 코드. –