0
我最近创建了一个工作簿,其中包含带有组合框的用户窗体,名称为“combobox1” 我有一个代码,它将范围为“B2:B .. ..“ 现在我想让它如何在一个组合框中的另一列shuld带来来自同一目录的数据,但范围为exp:”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
非常感谢你的回答,非常有用。我已经将combobox值链接到了范围“C9”,并且它将左列值返回给C9,并且它的OK,现在我想将第二列(右侧)链接到exp“B9”的单元格,并且我想要用于设置两个链接值的VBA代码。 –