Consulting

Results 1 to 7 of 7

Thread: Solved: Runtime error

  1. #1
    VBAX Regular
    Joined
    Jul 2011
    Posts
    33
    Location

    Solved: Runtime error

    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:

    [vba]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[/vba]

    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

  2. #2
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,455
    Location
    Can you post the workbook?
    ____________________________________________
    Nihil simul inventum est et perfectum

    Abusus non tollit usum

    Last night I dreamed of a small consolation enjoyed only by the blind: Nobody knows the trouble I've not seen!
    James Thurber

  3. #3
    VBAX Regular
    Joined
    Jul 2011
    Posts
    33
    Location
    It doesn't let me attach the file despite it's size is less than 1mb.

  4. #4
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,455
    Location
    Try zipping it.
    ____________________________________________
    Nihil simul inventum est et perfectum

    Abusus non tollit usum

    Last night I dreamed of a small consolation enjoyed only by the blind: Nobody knows the trouble I've not seen!
    James Thurber

  5. #5
    VBAX Regular
    Joined
    Jul 2011
    Posts
    33
    Location
    Done
    Attached Files Attached Files

  6. #6
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,455
    Location
    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?
    ____________________________________________
    Nihil simul inventum est et perfectum

    Abusus non tollit usum

    Last night I dreamed of a small consolation enjoyed only by the blind: Nobody knows the trouble I've not seen!
    James Thurber

  7. #7
    VBAX Regular
    Joined
    Jul 2011
    Posts
    33
    Location
    That was the problem. I didn't notice that the first column of the tables of all sheets was on the B column .

    Thank you very much

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •