Anouar ALMOUSLIH
Anouar ALMOUSLIH

Reputation: 29

I want to add rows to a ROWSOURCE automatically whenever i add new data

hope you're doing well. I'm having a problem regarding the addition of new rows to a rowsource in VBA excel. To put this in context, I have a Combobox that has multiple products, and each one is priced differently. I want to add a command button which allows me to add new products to that Combobox alongside the pricing elements.

('[Calculette_form.xlsm]Calcul'!$T7:$T64) this is the rowsource, I want that whenever I add a new product, the ($T64) would move automatically to ($T65) and so on I need your help, I'm kinda stuck here. Hope my explanation is clear (hope the picture will help)

Screenshot

I've tried count() before, Do loop...nothing really made sense. I just need the proper coding solution for it.

Upvotes: 0

Views: 190

Answers (1)

CDP1802
CDP1802

Reputation: 16184

Private Sub CommandButton1_Click()

    Dim rng As Range
    Set rng = Range(UserForm1.ListBox1.RowSource)
    UserForm1.ListBox1.RowSource = "'[Calculette_form.xlsm]Calcul'!" & _
              rng.Resize(rng.Rows.Count + 1, rng.Columns.Count).Address(0, 0)
              
End Sub

Upvotes: 1

Related Questions