Forum

Run-Time error '6':...
 
Notifications
Clear all

Run-Time error '6': Please let me guide for my vba error

5 Posts
2 Users
0 Reactions
88 Views
(@ishaq1978)
Posts: 3
Active Member
Topic starter
 

I am working on a project .The detail of my project and my problem  is given  below.

Available objects

  1. A Userform
  2. A List Box
  3. Three Combo Box
  4. One Text Box
  5. 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

 
Posted : 14/06/2021 7:28 am
(@fluff)
Posts: 36
Eminent Member
 

Change this

Dim i, X As Integer

to

Dim i As Long, X As Long

 
Posted : 14/06/2021 11:47 am
(@ishaq1978)
Posts: 3
Active Member
Topic starter
 

Thanks for your reply.But my problem is still here.And now the code is not responding.

 
Posted : 14/06/2021 12:51 pm
(@fluff)
Posts: 36
Eminent Member
 

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

 
Posted : 14/06/2021 1:45 pm
(@ishaq1978)
Posts: 3
Active Member
Topic starter
 

Its Ok now.Thanks to share your Knowledge

 
Posted : 14/06/2021 2:37 pm
Share: