Active Member
June 13, 2021
I am working on a project .The detail of my project and my problem is given below.
Available objects
- A Userform
- A List Box
- Three Combo Box
- One Text Box
- A Sheet (Sheet1)
What is my Objectives
I Want to get sum in the text box from the list box based on the selection of three combo box.
What is my Problem
I have write all the code for every object .Now i write code to get sum in the textbox according to the selection from the three combobox ,i got error
"Run-time error '6':
The code for first combo box is
<Dim i, X As Integer
Dim Mylist As String
With Me.ListBox1
For i = 1 To .ListCount - 1
For X = i To .ListCount - 1 ' I got error on this line
If .List(X, 0) = Me.VCHBox Then
For c = 0 To 6
Mylist = .List(X, c)
.List(X, c) = .List(i, c)
.List(i, c) = Mylist
Me.ListBox1.Selected(i) = True
Next c
End If
Next X
Next i
Dim M As Integer
Dim SUM, SUM1 As Double
For M = 1 To .ListIndex()
SUM = SUM + Val(.List(M, 3))
SUM1 = SUM1 + Val(.List(M, 4))
Next M
Me.TextBox1 = Format(SUM1, "#####.00")
End With
End Sub/>
Image and file are given in attachment .
I request you to please help me to handle this error.Because my project is stopped due this issue.
Thanks
July 31, 2020
The code is not responding because you are loading the listbox with an array of 1,000,000 rows. Try it like this instead.
Private Sub UserForm_Initialize()
Dim c As Long
c = Range("A1").End(xlToRight).Column
With Range("A1", Range("A" & Rows.Count).End(xlUp)).Resize(, c)
Me.ListBox1.List = .Value
End With
Me.ListBox1.ColumnCount = c
Me.ListBox1.TextAlign = fmTextAlignLeft
Me.ListBox1.Selected(0) = False
End Sub
1 Guest(s)