ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Code fix need help please (https://www.excelbanter.com/excel-programming/336322-code-fix-need-help-please.html)

cody

Code fix need help please
 
I am using this code to fill a combobox list. However, somehow the values are
getting added onto previous values and the range is not emptying before it
adds items. How do I fix this.

Dim thiscel As Range

ComboBox1.ListFillRange = ""

For Each thiscel In Sheets("Defaults").Range("R344:R362")
If Len(thiscel) 0 Then
Sheets("Input").ComboBox1.AddItem thiscel.Value
End If
Next


Jim Thomlinson[_4_]

Code fix need help please
 
Add this line of code...

ComboBox1.Clear

To clear any previous additions to the combo box.
--
HTH...

Jim Thomlinson


"Cody" wrote:

I am using this code to fill a combobox list. However, somehow the values are
getting added onto previous values and the range is not emptying before it
adds items. How do I fix this.

Dim thiscel As Range

ComboBox1.ListFillRange = ""

For Each thiscel In Sheets("Defaults").Range("R344:R362")
If Len(thiscel) 0 Then
Sheets("Input").ComboBox1.AddItem thiscel.Value
End If
Next


cody

Code fix need help please
 
Thank you Jim. I have been racking my brain of such a simple fix.


"Jim Thomlinson" wrote:

Add this line of code...

ComboBox1.Clear

To clear any previous additions to the combo box.
--
HTH...

Jim Thomlinson


"Cody" wrote:

I am using this code to fill a combobox list. However, somehow the values are
getting added onto previous values and the range is not emptying before it
adds items. How do I fix this.

Dim thiscel As Range

ComboBox1.ListFillRange = ""

For Each thiscel In Sheets("Defaults").Range("R344:R362")
If Len(thiscel) 0 Then
Sheets("Input").ComboBox1.AddItem thiscel.Value
End If
Next



All times are GMT +1. The time now is 10:30 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com