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