# ListBox adding data on top of previous registers.

#### Jom

##### New Member
Greetings colleagues ... I`m a beginner in VBA. Can you help me?
THE PROBLEM:
My ListBox, when add more registers, it adds on top of the registers that were already added, instead of inserting in the lines below.

HOW IT WORKS ON USERFORM:

TextBox1 to insert a number;
TextBox2 to enter a quantity;
3 OpttionButtons, to choose a color.

When clicking on CommandButton1 the data is sent to ListBox1 inaccording to the criteria of TextBoxs and OptionsButtons.
Example:

Textbox1 = 777 (any number)
TextBox2 = 3 (Qty.)
OptionButton1 = Green (Color)

THE RESULT IN ListBox1: (2 Columns)
777 Green
778 Green
779 Green

It is working correctly, but the new registers are add on top of the previous ones. How can I solve this?

MY CODE:

Private Sub CommandButton1_Click()
Dim Number As Double
Dim Color As String
Dim Quantity as Long
Dim i As Long

Number = Val (TextBox1)
Quantity = Val (TextBox2)
ListBox1.Clear

If OptionButton1 = True Then Color = "Green"
If OptionButton2 = True Then Color = "Blue"
If OptionButton3 = True Then Color = "Black"

For i = 1 To quantity
ListBox1.List (ListBox1.ListCount - 1, 0) = Number
ListBox1.List (ListBox1.ListCount - 1, 1) = Color

Number = Number + 1

End Sub

It is working correctly, but the new registers are add on top of the previous ones. How can I solve this?
Any help, I'll be happy.
Att. Jom

#### Jom

##### New Member
"Peter _SSs" and "diddi",
Thank you very much for help and suggestions. [Solved]

### 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.

Replies
42
Views
557
Replies
7
Views
393
Replies
1
Views
92
Replies
8
Views
53
Replies
2
Views
490

1,130,152
Messages
5,640,423
Members
417,142
Latest member
andygame

### 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?

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