Macro para solucionar nombre ambiguo

Me sale el siguiente error "Error de compilación: Se ha detectado un nombre ambiguo: UserForm_Activate". Adjunto código fuente para que me brinde su apoyo.

Private Sub ComboBox2_Change()
    Set h = Sheets("Datos")
    u = h.Range("C" & Rows.Count).End(xlUp).Row
End Sub
Private Sub UserForm_Activate()
    Set h = Sheets("Datos")
    If h.AutoFilterMode Then h.AutoFilterMode = False
    For i = 2 To h.Range("C" & Rows.Count).End(xlUp).Row
        Call Agregar(ComboBox2, h.Cells(i, "C").value)
    Next
End Sub
Private Sub ComboBox4_Change()
    Set h = Sheets("Datos")
    u = h.Range("A" & Rows.Count).End(xlUp).Row
End Sub
Private Sub UserForm_Activate()
    Set h = Sheets("Datos")
    If h.AutoFilterMode Then h.AutoFilterMode = False
    For i = 2 To h.Range("A" & Rows.Count).End(xlUp).Row
        Call Agregar(ComboBox4, h.Cells(i, "A").value)
    Next
End Sub

2 respuestas

Respuesta
1

Hol.a

Los eventos son únicos para los objetos y tú estás colocando dos eventos "Activate" en el mismo "UserForm", cámbialo:

Private Sub UserForm_Activate()
    Set h = Sheets("Datos")
    If h.AutoFilterMode Then h.AutoFilterMode = False
    For i = 2 To h.Range("C" & Rows.Count).End(xlUp).Row
        Call Agregar(ComboBox2, h.Cells(i, "C").value)
    Next
    For i = 2 To h.Range("A" & Rows.Count).End(xlUp).Row
        Call Agregar(ComboBox4, h.Cells(i, "A").value)
    Next
End Sub

Salu2

Abraham Valencia

Respuesta
1

Has programado dos eventos iguales UserForm_Activate(), por ello te sale el error de ambigüedad.

Lo que debes hacer es colocar los procedimientos en un sólo evento y se soluciona el problema.

Private Sub UserForm_Activate()
    Set h = Sheets("Datos")
    If h.AutoFilterMode Then h.AutoFilterMode = False
    For i = 2 To h.Range("C" & Rows.Count).End(xlUp).Row
        Call Agregar(ComboBox2, h.Cells(i, "C").value)
    Next
    For i = 2 To h.Range("A" & Rows.Count).End(xlUp).Row
        Call Agregar(ComboBox4, h.Cells(i, "A").value)
    Next
End Sub

Espero que te sirva de ayuda y pueda estar acorde a tu necesidad. Cualquier consulta estaré pendiente.

Por favor no olvidar de valorar las respuestas.

Añade tu respuesta

Haz clic para o

Más respuestas relacionadas