0

enter image description hereHi,

I have a userform in VBA using dropdown list there & I want data in dropdown button from a list already created in excel sheet2. But don't know how to do this. Please help me & Thanks a lot in advance.

Private Sub ComboBox1_Change()
Dim hq As String, asheet As Worksheet, acell As Range
Dim lrow As Double, test As String
Set asheet = ThisWorkbook.Sheets(2)

hq = ComboBox1.Value
Set acell = asheet.Range("$AQ$1:$FR$95").Find(what:=hq, LookIn:=xlValues, lookat:=xlPart, searchorder:=xlByRows, searchdirection:=xlNext, MatchCase:=False, searchformat:=False)
asheet.Activate
acell.Activate
Selection.End(xlDown).Select
lrow = Selection.Row + 1

ThisWorkbook.Sheets(3).Activate
End Sub

Private Sub CommandButton1_Click()
If CommandButton1 = True Then
Cells(lrow, acell.Column).Value = TextBox1 & "-" & TextBox2
End If
End Sub

Private Sub TextBox1_Change()
Dim txt1 As String
txt1 = TextBox1.Value
Debug.Print txt1

End Sub

Private Sub TextBox2_Change()
Dim txt2 As String
txt2 = TextBox2.Value
Debug.Print txt2
End Sub

Private Sub UserForm_Click()

End Sub
Nafis
  • 113
  • 1
  • 11
  • Possible duplicate of [How do I populate a combo box from a column in my excel spread sheet?](https://stackoverflow.com/questions/14392122/how-do-i-populate-a-combo-box-from-a-column-in-my-excel-spread-sheet) or [excel vba dynamically populate combobox](https://stackoverflow.com/questions/39311964/excel-vba-dynamically-populate-combobox) – Pᴇʜ Jan 18 '19 at 09:00

1 Answers1

0

Below query will work for you

ComboboxName.List = Sheets("Sheet2").Range("F2:F<SpecifiytheNumber>").Value

Venkatesh R
  • 515
  • 1
  • 10
  • 27
  • even when I am coding with combobox1 .additem "test" end with not showing anything in dropdown list – Nafis Jan 18 '19 at 09:48
  • Please go through my codes, how to run all of them together please help – Nafis Jan 18 '19 at 11:01
  • Create "Initialize" event for UserForm and add the code. The list has to be loaded when the form is initialized. ' Private Sub UserForm_Initialize() Combobox1.List = Sheets("Sheet2").Range("F2:F10").Value End Sub ' – Venkatesh R Jan 19 '19 at 02:54