I wonder if anybody can help with this please
I have some data that I have imported into my workbook from an excel workbook using get data then get data from file.
I have a combobox which is linked to a cell, its so I can search the first column of the imported data then select it and it will enter it into the linked cell. The problem is when I open up the template and I click on the arrow on the side of the combobox it just shows blank rather than a dropdown with the list in it, if I start to search in the combobox its fine it just acts like a dropdown box and I can select the data I need and it enters into the linked cell all OK.
I know/think I have to put a range name into the ListFillRange property in the combo box but cannot get it to work, it will not accept my range names.
I have created a new name RangeDataList and referred it to the named range MainData but I cannot get the ListFillRange property of the combobox to accept it.
I actually have two combo boxes on the same sheet but once I know what to do, I can apply the same to the 2nd combo box
I have attached the code for both combo boxes & pics of the properties & name manager boxes
Any help would be appreciated
I have some data that I have imported into my workbook from an excel workbook using get data then get data from file.
I have a combobox which is linked to a cell, its so I can search the first column of the imported data then select it and it will enter it into the linked cell. The problem is when I open up the template and I click on the arrow on the side of the combobox it just shows blank rather than a dropdown with the list in it, if I start to search in the combobox its fine it just acts like a dropdown box and I can select the data I need and it enters into the linked cell all OK.
I know/think I have to put a range name into the ListFillRange property in the combo box but cannot get it to work, it will not accept my range names.
I have created a new name RangeDataList and referred it to the named range MainData but I cannot get the ListFillRange property of the combobox to accept it.
I actually have two combo boxes on the same sheet but once I know what to do, I can apply the same to the 2nd combo box
I have attached the code for both combo boxes & pics of the properties & name manager boxes
Any help would be appreciated
VBA Code:
'sheet's name where the list (for combobox) is located. [in the sample: sheet "data"]
Private Const sList As String = "MainData"
Private Const s2List As String = "Sub_Contractors"
'cell where the list start [in the sample: cell A2 in sheet "Data" ]
Private Const sCell As String = "A2"
Private Const s2Cell As String = "A2"
'the linked cell
Private Const xCell As String = "B15"
Private Const x2Cell As String = "C3"
Private vList
Private Sub ComboBox1_Change()
Dim z, ary
With ComboBox1
If .Value <> "" And IsError(Application.Match(.Value, vList, 0)) Then
With Sheets("Main Data")
ary = Application.Transpose(.Range(sCell, .Cells(.Rows.Count, .Range(sCell).Column).End(xlUp)).Value)
End With
For Each z In Split(.Value, " ")
ary = Filter(ary, z, True, vbTextCompare)
Next
.List = ary
.DropDown
ElseIf Not IsError(Application.Match(.Value, vList, 0)) Then
Range(xCell) = .Value
Else
Range(xCell) = .Value
.List = vList
End If
End With
End Sub
Private Sub ComboBox1_GotFocus()
With Sheets("Main Data")
vList = Application.Transpose(.Range(sCell, .Cells(.Rows.Count, .Range(sCell).Column).End(xlUp)).Value)
End With
ComboBox1.MatchEntry = fmMatchEntryNone
ComboBox1.Value = ""
'ComboBox1.ListRows = 10 'to show how many item
End Sub
Private Sub ComboBox2_Change()
Dim z, ary
With ComboBox2
If .Value <> "" And IsError(Application.Match(.Value, v2List, 0)) Then
With Sheets("Sub Contractors")
ary = Application.Transpose(.Range(s2Cell, .Cells(.Rows.Count, .Range(s2Cell).Column).End(xlUp)).Value)
End With
For Each z In Split(.Value, " ")
ary = Filter(ary, z, True, vbTextCompare)
Next
.List = ary
.DropDown
ElseIf Not IsError(Application.Match(.Value, vList, 0)) Then
Range(x2Cell) = .Value
Else
Range(x2Cell) = .Value
.List = vList
End If
End With
End Sub
Private Sub ComboBox2_GotFocus()
With Sheets("Sub Contractors")
vList = Application.Transpose(.Range(s2Cell, .Cells(.Rows.Count, .Range(s2Cell).Column).End(xlUp)).Value)
End With
ComboBox2.MatchEntry = fmMatchEntryNone
ComboBox2.Value = ""
'ComboBox2.ListRows = 10 'to show how many item
End Sub