how to use ComboBox1.List = Worksheets("SHEET1").Range("A1:A50").Value in this code

moradiyavm

New Member
Joined
Dec 31, 2016
Messages
2
Private Sub ComboBox1_KeyPress(ByVal KeyAscii As MSForms.ReturnInteger)
Call DropDown(KeyAscii.Value)
End Sub


Private Sub ComboBox1_KeyUp(ByVal KeyCode As MSForms.ReturnInteger, ByVal Shift As Integer)
If KeyCode.Value = 8 Then
Call DropDown(KeyCode.Value)
End If
End Sub


Private Sub UserForm_Initialize()
Dim MyArr As Variant
MyArr = Array("Adam 001", "Adam 002", "Apple 001", "Apple 002", "Banana 001", "Banana 002", "Orange 001", "Orange 002")
ComboBox1.List = MyArr
End Sub


Sub DropDown(NKey As Integer)
If NKey <> 8 Then
MyV = Chr(NKey)
MyC = 1
Else
MyV = ""
MyC = 0
End If
Dim MyArr As Variant
MyArr = Array("Adam 001", "Adam 002", "Apple 001", "Apple 002", "Banana 001", "Banana 002", "Orange 001", "Orange 002")
For a = LBound(MyArr) To UBound(MyArr)
If UCase(Left(MyArr(a), Len(ComboBox1.Value) + MyC)) = UCase(ComboBox1.Value & MyV) Then
MyStr = MyStr & MyArr(a) & "~"
End If
Next a
If MyStr <> "" Then MyNewArr = Split(MyStr, "~", , vbBinaryCompare)
On Error Resume Next
MyL = UBound(MyNewArr)


If MyL <> "" Then
ComboBox1.List = MyNewArr
Else
ComboBox1.List = Split("", "")
End If
End Sub
 

Excel Facts

Convert text numbers to real numbers
Select a column containing text numbers. Press Alt+D E F to quickly convert text to numbers. Faster than "Convert to Number"
Private Sub ComboBox1_KeyPress(ByVal KeyAscii As MSForms.ReturnInteger)
Call DropDown(KeyAscii.Value)
End Sub


Private Sub ComboBox1_KeyUp(ByVal KeyCode As MSForms.ReturnInteger, ByVal Shift As Integer)
If KeyCode.Value = 8 Then
Call DropDown(KeyCode.Value)
End If
End Sub


Private Sub UserForm_Initialize()
Dim MyArr As Variant, i As Long
MyArr = Worksheets("SHEET1").Range("A1:A50").Value
For i = 1 To UBound(MyArr, 1)
ComboBox1.AddItem MyArr(i, 1)
Next
End Sub


Sub DropDown(NKey As Integer)
If NKey <> 8 Then
MyV = Chr(NKey)
MyC = 1
Else
MyV = ""
MyC = 0
End If
Dim MyArr As Variant
MyArr = Worksheets("SHEET1").Range("A1:A10").Value
For a = LBound(MyArr) To UBound(MyArr)
If UCase(Left(MyArr(a), Len(ComboBox1.Value) + MyC)) = UCase(ComboBox1.Value & MyV) Then 'subscript out of range
MyStr = MyStr & MyArr(a) & "~"
End If
Next a
If MyStr <> "" Then MyNewArr = Split(MyStr, "~", , vbBinaryCompare)
On Error Resume Next
MyL = UBound(MyNewArr)


If MyL <> "" Then
ComboBox1.List = MyNewArr
Else
ComboBox1.List = Split("", "")
End If
End Sub
 
Upvote 0

Forum statistics

Threads
1,214,653
Messages
6,120,755
Members
448,989
Latest member
mariah3

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top