Spliting value of Combobox

NimishK

Well-known Member
Joined
Sep 4, 2015
Messages
688
Anyone has idea to Split the value of Combobox.Text with smoother functioning
I tried the following
Code:
Private Sub UserForm_Initialize()
   Combobox1.List = Worksheets("Sheet1").Range("A2").CurrentRegion.Offset(1).Value
End Sub

Private Sub Combobox1_Click()

  Dim splitValue() As String
  Dim comboListName As String
  Dim idx As Long

comboListName = Combobox1.Text 

 idx = Combobox1.ListIndex
 splitValue = Split(comboListName, " ")
 Combobox1.Text =splitValue(0) 
''''Basically to read value of 1st most left values ie why i used splitvalue(0)
If idx <> -1 Then
ComboBox1.Text = splitValue(0)
End If
End Sub

Combobox1.Drop button style = 1

Got Stuck with above coding only and not moved further on
As it displays the two Separate values in ComboBox
When Clicked with Down Arrow Key button it only displays 1st value and really cannot go further down
Also have to select the value when dropdown. Really Event is not smooth triggering
With selection on the particular item it shows that single value but with down arrow key not happening

Regards
NimishK
 
Last edited:

Excel Facts

How to find 2nd largest value in a column?
MAX finds the largest value. =LARGE(A:A,2) will find the second largest. =SMALL(A:A,3) will find the third smallest
Re: Spliting value of Combobox : Not working smoothly

Could you please explain what exactly you are trying to do, as it is not clear from your op.
 
Upvote 0
Re: Spliting value of Combobox : Not working smoothly

Well Fluff you need to copy the above and try it your end and Try clicking in ComboxBox_click()

Basically i am trying to seperate the values of Column A which has two values seperated by blank space and so the left value of column A trying to get on Combobox.
 
Last edited:
Upvote 0
Re: Spliting value of Combobox : Not working smoothly

What's the point of trying code that doesn't work, when I have no idea what you are trying to do? ;)
Are you trying to populate the combo with all the values from col A after you have split them?
 
Upvote 0
Re: Spliting value of Combobox : Not working smoothly

Are you trying to populate the combo with all the values from col A after you have split them?
Yes.
trying to get left value of column A into Combobox. but Combo not working as i desire
 
Last edited:
Upvote 0
Re: Spliting value of Combobox : Not working smoothly

Try
Code:
Private Sub UserForm_Initialize()
   Dim ary As Variant
   Dim i As Long
   ary = Worksheets("Sheet1").Range("A2").CurrentRegion.Value
   For i = 2 To UBound(ary)
   ComboBox1.AddItem Split(ary(i, 1))(0)
   Next i
End Sub
and remove the code from the combobox event
 
Upvote 0
Re: Spliting value of Combobox : Not working smoothly

That was really Excellent one :beerchug:
Ok i tried the following below code too but i get Subscript out of range
Code:
Dim Arr As Variant
Arr = Array("abc def", "ghi jkl", "mno pqr")
Me.ComboBox1.Clear
Me.ComboBox1.List = Arr

 Dim i As Long
   For i = 1 To UBound(Arr)
   ComboBox1.AddItem Split(Arr(i, 1))(0)
   Next i
 
Last edited:
Upvote 0
Re: Spliting value of Combobox : Not working smoothly

Where is that code located & what are you trying to do?
 
Upvote 0
Re: Spliting value of Combobox : Not working smoothly

The code is in UF_Initialize.

I was trying the same thing to get Left values stored in Array in combobox.
Code:
Arr = Array("abc def", "ghi jkl", "mno pqr")
To get ABC
GHI
MNO
in combobox list
Your help will be appreciated
 
Upvote 0
Re: Spliting value of Combobox : Not working smoothly

Try
Code:
Dim Arr As Variant
Arr = Array("abc def", "ghi jkl", "mno pqr")
Me.ComboBox1.Clear

 Dim i As Long
   For i = 0 To UBound(Arr)
      ComboBox1.AddItem Split(Arr(i))(0)
   Next i
 
Upvote 0

Forum statistics

Threads
1,223,903
Messages
6,175,287
Members
452,631
Latest member
a_potato

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