0

I am trying to add a search box that will autocomplete the name of something when a user is typing a word. The table I made that list all the words I wish to show has been made in another sheet inside the name workbook.

This is the code I am using:

Private Sub ComboBox1_Click()

    Dim wbExternal As Workbook 'the other workbook with the data
    Dim wsExternal As Worksheet 'the worksheet in the other workbook
    Dim lnLastRow As Long   'last row on the worksheet
    Dim rngExternal As Range 'range of data from RowSource

    Set wbExternal = Application.Workbooks("New Material Search - 2020 Draft.xlsm")
    Set wsExternal = wbExternal.Worksheets("Man_Prod")
    lngLastRow = wsExternal.Range("A" & wsExternal.Rows.Count).End(xlUp).Row
    Set rngExternal = wsExternal.Range("A2:A" & CStr(lngLastRow))

    ComboBox1 = rngExternal.Address(External:=True)

End Sub

However, in the ComboBox all I get is '[New Material Search - 2020 Draft.xlsm]Man_Prod'!$A$2:$A$6 and an error that says

This Formula is missing a range reference or a defined name.

The ComboBox should also have a dropdown list that shows all the words from the table on the other sheet.

0

1 Answer 1

1

You need to create a loop and add all the values from the external range to ComboBox1. So instead of ComboBox1 = rngExternal.Address(External:=True) you should use something like this:

For r in rngExternal
  ComboBox1.AddItem r.Value
Next r

Read more here: https://www.contextures.com/Excel-VBA-ComboBox-Lists.html

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.