• Hi All

    Please note that at the Chandoo.org Forums there is Zero Tolerance to Spam

    Post Spam and you Will Be Deleted as a User

    Hui...

  • When starting a new post, to receive a quicker and more targeted answer, Please include a sample file in the initial post.

Control variable already in use

Muchemi

New Member
hello I have this code but when I run the code I get error "control variable already in use" kindly help

>>> use code - tags <<<
Code:
Dim sh As Worksheet
Dim i As Long
Me.ListBox1.Clear
Set sh = Sheets("SG_Sheet1")
Me.ListBox1.AddItem
For a = 1 To 6
Me.ListBox1.List(0, a - 1) = sh.Cells(1, a)
Next a
Me.ListBox1.Selected(0) = True

For i = 2 To sh.Range("A1000000").End(xlUp).Offset(1, 0).Row
For j = 1 To 6
H = Application.WorksheetFunction.CountIf(sh.Range("A" & 2, "F" & i), _
sh.Cells(i, f))
If H = 1 And LCase(sh.Cells(i, f)) = LCase(Me.TextBox1) Or H = 1 And _
sh.Cells(i, f) = Val(Me.TextBox1) Then
For x = 1 To 6
Me.ListBox1.AddItem
For x = 1 To 6
Me.ListBox1.List(ListBox1.ListCount - 1, x - 1) = sh.Cells(i, x)
Next x
End If
Next j
Next i
 
Last edited by a moderator:

AlanSidman

Well-Known Member
When you get the error message, click on Debug and tell us which line of code is highlighted and tell us the complete error message.

I am guessing these lines are thee issue. Cannot have the For x line more than once and have only one Next x.

Code:
For x = 1 To 6
Me.ListBox1.AddItem
For x = 1 To 6
 
Top