Share via

VBA Combo Box error

Anonymous
2012-04-03T15:54:59+00:00

Hi.

When  I initialise a user form I am populating a combo box as follows which works the first time round:

With cboBusiness

        .AddItem "Hulu Limited"

        .AddItem "Moustraining Ltd"

        .AddItem "The Modbury Group"

    End With

Once the user has pressed the Save button the data is written to the worksheet OK.

the user then presses a Clear button which is supposed to clear the data and then call the userform initialisation so that they can enter a second record.

Private Sub btnClear_Click()

    cboBusiness.Value = ""

    txtQty.Value = ""

    txtAvWt.Value = ""

    txtCost.Value = ""

    txtRecQty.Value = ""

    txtSDQty.Value = ""

    txtNetCost.Value = ""

    Call UserForm_Initialize

End Sub,

All of the data is being cleared a;part from the data held in the combo box , which is then being doubled up. 

Can anyone tell me what I have got wrong

many thanks

A

Microsoft 365 and Office | Excel | For home | MacOS

Locked Question. This question was migrated from the Microsoft Support Community. You can vote on whether it's helpful, but you can't add comments or replies or follow the question.

0 comments No comments

Answer accepted by question author

Anonymous
2012-04-03T16:32:27+00:00

The .Value property of a Combobox is not the same as the .List property - you can change the Value without changing the .List.

You could use something like

    With cboBusiness

.Text = ""

For i = .ListCount - 1 To 0 Step -1

.RemoveItem i

Next i

End With 

or, more simply,

cboBusiness.Clear

Was this answer helpful?

0 comments No comments

1 additional answer

Sort by: Most helpful
  1. Anonymous
    2012-04-03T17:17:46+00:00

    Very many thanks

    Was this answer helpful?

    0 comments No comments