Al accionar botón “Buscar” me regresa error “No se ha definido la variable”

Tengo esta macro que es para buscar en las pestañas del libro el “Municipio” y dentro de este un “Proveedor” pero me regresa error “No se ha definido la variable”. He cambiado a varias y sigue igual… pido de nuevo tu colaboración para buscar el error o cambio de alguna función… Muchas gracias por tu atención.

Te adjunto la macro…

Private Sub ComboBox1_enter()

ComboBox1. AddItem "MpAlamos"

ComboBox1. AddItem "MpAconchi"

ComboBox1. AddItem "MpAPrieta"… ottros

End sub

Private Sub CommandButton2_Click() ' CONSULTAR

    Application.ScreenUpdating = False

    ‘ Dim Mp As String

   ‘ Mp = ComboBox1.Value

    For Each h In Sheets

        n = h.Name

        If UCase(h.Name) = UCase(ComboBox1) Then

            existe = True

            Exit For

        End If

    Next

    If existe = False Then

        MsgBox "La hoja seleccionada no existe", vbCritical, "SELCCIONAR mpio"

        Exit Sub

        ComboBox1.SetFocus

    End If

'IDENTIFICA NOMBRES

    Set h1 = Sheets(ComboBox1.Value)

           TextBox9 = h1.Range("A1") ' MUNICIPIO

    Set b = h1.Columns("B").Find(ComboBox2, lookat:=xlWhole)

       If Not b Is Nothing Then

           TextBox10 = h1.Cells(b.Row, "B") 'PROVEEDOR

       End If

Application.ScreenUpdating = True

End Sub

1 Respuesta

Respuesta
1

Tienes esto al principio de las macros:

Option Explicit

Esa instrucción se utiliza para verificar que todas las variables estén declaradas. En VBA de excel no es necesario declarar las variables, por lo tanto puedes borrar la línea Option Explicit.

Añade tu respuesta

Haz clic para o

Más respuestas relacionadas