PDA

View Full Version : Solved: Runtime error



pepe90
08-02-2011, 05:46 AM
Hello, I have a problem with a code because Im getting a runtime error (error defined by the object), but the real issue is that it doesn't mark an specific line so I have to bother you posting all the code:

Private Sub UserForm_Initialize()
Dim lista() As String
Dim i, j, k, f, n As Integer
Dim fields(1 To 4) As Integer
Dim combo As Variant
With ActiveSheet
i = 1
Do While .Cells(i, 1) <> "# DE GUIA"
i = i + 1
Loop
j = 1
k = 1
Do While .Cells(i, j) <> "DOBLA"
Select Case .Cells(i, j)
Case "ENTRADA"
fields(k) = j
k = k + 1
Case "SALIDA"
fields(k) = j
k = k + 1
Case "MAQUINA"
fields(k) = j
k = k + 1
End Select
j = j + 1
Loop
fields(k) = j
For k = 1 To 4
Select Case k
Case 1
combo = entrada.Object
Case 2
combo = salida.Object
Case 3
combo = maquina.Object
Case 4
combo = dobla.Object
End Select
f = i + 1
n = 0
ReDim lista(1 To 1)
Do While .Cells(f, 1) <> ""
palabra = .Cells(f, 1)
yaEsta = encontrar(palabra, lista)
If yaEsta < 0 Then
n = n + 1
ReDim Preserve lista(1 To n)
lista(n) = palabra
combo.AddItem palabra
End If
f = f + 1
Loop
Next
End With
End Sub

entrada, salida, maquina and dobla are the names of comboboxes on the form. encontrar is a function I created and I don't think there is the problem because I disabled that line and stiil get the same message. The idea of the macro is basically to put on the combobox displaying list the list you get when you use filters on a worksheet. Any idea of where is the mistake?

Thanks in advance

Bob Phillips
08-02-2011, 07:19 AM
Can you post the workbook?

pepe90
08-02-2011, 07:33 AM
It doesn't let me attach the file despite it's size is less than 1mb.

Bob Phillips
08-02-2011, 08:26 AM
Try zipping it.

pepe90
08-02-2011, 08:46 AM
Done ;)

Bob Phillips
08-02-2011, 11:13 AM
It is failing on the first loop, it never finds that value so it loops until the counter blows. Which sheet is it meant to be on, what column should it test, and what should happen if there is no match?

pepe90
08-02-2011, 12:24 PM
That was the problem. I didn't notice that the first column of the tables of all sheets was on the B column :doh:.

Thank you very much