problem repeat rowsorce combobox every time click another cell

abdelfattah

Well-known Member
Joined
May 3, 2019
Messages
1,429
Office Version
  1. 2019
  2. 2010
Platform
  1. Windows
hello
i have a problem i insert activeX combobox into sheet and i add this code every thing is ok in the first time but when i move from combobox to any cell i found the list in combobox is repeat continuously when i move to any cell
VBA Code:
Private Sub ComboBox1_DropButtonClick()
With ComboBox1
.AddItem "jan"
.AddItem "feb"
.AddItem "mar"
.AddItem "apr"
.AddItem "may"
.AddItem "jun"
.AddItem "jul"
.AddItem "aug"
.AddItem "sep"
.AddItem "oct"
.AddItem "nov"
.AddItem "dec"
End With

End Sub

i hope any body help
thanks
 

Excel Facts

Which came first: VisiCalc or Lotus 1-2-3?
Dan Bricklin and Bob Frankston debuted VisiCalc in 1979 as a Visible Calculator. Lotus 1-2-3 debuted in the early 1980's, from Mitch Kapor.
I don't understand why you load the combo every time you select it, but with the following you can solve it:

VBA Code:
Private Sub ComboBox1_DropButtonClick()
  With ComboBox1
    .Clear
    .AddItem "jan"
    .AddItem "feb"
    .AddItem "mar"
    .AddItem "apr"
    .AddItem "may"
    .AddItem "jun"
    .AddItem "jul"
    .AddItem "aug"
    .AddItem "sep"
    .AddItem "oct"
    .AddItem "nov"
    .AddItem "dec"
  End With
End Sub
 
Upvote 0
hi, Dante actually i don't understand this statement

I don't understand why you load the combo every time you select it
my code supposes load the combobox one time and works normally without any repeat every time i select it
but when add ".clear" it become the combobox is empty when i choose item not show the selected item
 
Upvote 0
Try this
VBA Code:
Private Sub ComboBox1_DropButtonClick()
  Dim dato
  With ComboBox1
    dato = .Value
    .Clear
    .AddItem "jan"
    .AddItem "feb"
    .AddItem "mar"
    .AddItem "apr"
    .AddItem "may"
    .AddItem "jun"
    .AddItem "jul"
    .AddItem "aug"
    .AddItem "sep"
    .AddItem "oct"
    .AddItem "nov"
    .AddItem "dec"
    .Value = dato
  End With
End Sub
 
Upvote 0
Solution
yes, that works , could you explain me why my code doesn't work correctly in the normal situation and when you define the variable what's the type and what means this at begening code and end code?
dato = .Value
 
Upvote 0
I declare the variable, you should always declare variables. It should actually be
Dim data as string
I was missing that part.

At the beginning dato = .value, it passes the value of the combo to the variable "dato" and at the end the content of the "dato" is returned to the combo.
 
Upvote 0
Glad we could help & thanks for the feedback
 
Upvote 0

Forum statistics

Threads
1,214,622
Messages
6,120,580
Members
448,972
Latest member
Shantanu2024

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