ListBox adding data on top of previous registers.

Jom

New Member
Joined
Feb 19, 2021
Messages
36
Office Version
  1. 2016
Platform
  1. Windows
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.AddItem
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
 
"Peter _SSs" and "diddi",
Thank you very much for help and suggestions. [Solved]
 
Upvote 0

Excel Facts

Easy bullets in Excel
If you have a numeric keypad, press Alt+7 on numeric keypad to type a bullet in Excel.

Forum statistics

Threads
1,223,236
Messages
6,170,912
Members
452,366
Latest member
TePunaBloke

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