Al cargar mis datos con un botón Buscar mi combobox dependiente ya no funciona en su totalidad.

Tengo un botón BUSCAR que me llena los datos de mi formulario, los 3 primeros datos van en textbox y los otros 3 en combobox dependientes. Me llena bien los datos pero cuando quiero modificar los datos de los combobox no me trae del combobox3…
Solo cuando hago llenar los datos con el botón BUSCAR y quiero modificar dichos datos lo que no me trae el tercer combobox, sin buscar ningún dato funciona todo bien, como puedo hacer para que me funcione mi combobox dependiente en su totalidad aun cargando los datos con el botón BUSCAR..?

Este seria mi código de BUSCAR
Private Sub BUSCAR_Click()
Application.ScreenUpdating = False
Sheets("hoja1").Select
If TextBox1 = "" Then
MsgBox "Coloca algún dato para buscar", vbOKOnly + vbInformation, "AVISO"
TextBox1.SetFocus
Exit Sub
End If
Set rango = Range("A:A").Find(What:=TextBox1, _
LookAt:=xlWhole, LookIn:=xlValues)
If rango Is Nothing Then
MsgBox "El dato no fue encontrado", vbOKOnly + vbInformation, "AVISO"
TextBox1 = "": TextBox1.SetFocus
Exit Sub
Else
TextBox2 = Range("B" & rango.Row)
TextBox3 = Range("C" & rango.Row)
ComboBox1 = Range("D" & rango.Row)
ComboBox2 = Range("E" & rango.Row)
ComboBox3 = Range("F" & rango.Row)
End If
End Sub

y este el código del combobox dependientes
Private Sub ComboBox1_Change()
Application.ScreenUpdating = False
ComboBox2.Clear
Column = ComboBox1.ListIndex + 1
On Error Resume Next
With Hoja2
ComboBox2.List = .Range(.Cells(2, Column), .Cells(2, Column).End(xlDown)).Value
End With
On Error GoTo 0
End Sub


Private Sub ComboBox2_Change()
Application.ScreenUpdating = False
ComboBox3.Clear
valor = ComboBox2.Value
Set busca = ActiveSheet.Range("A5:D5").Find(valor, LookIn:=xlValues, LookAt:=xlWhole)
If Not busca Is Nothing Then
busca.Select
ActiveCell.Offset(1, 0).Select
Do While ActiveCell.Value <> ""
ComboBox3.AddItem ActiveCell.Value
ActiveCell.Offset(1, 0).Select
Loop
End If
End Sub

1 respuesta

Respuesta
1

Puedes enviarme un archivo con ejemplos y con la macro para hacer pruebas.
Mi correo [email protected]

Ya te envíe el archivo en tu correo...desde ya gracias

Saludos

Ya te envié el archivo corregido a tu correo.

En la macro están comentadas las líneas que agregué, sólo faltaban unos detalles.

Saludos. Dam

Si es lo que necesitas.

Muchísimas Gracias era justo lo que necesitaba, Gracias... :)

Agrego el código

Dim rango As Range
Private Sub ComboBox1_Change()
Application.ScreenUpdating = False
ComboBox2.Clear
Column = ComboBox1.ListIndex + 1
On Error Resume Next
With Hoja2
    ComboBox2.List = .Range(.Cells(2, Column), .Cells(2, Column).End(xlDown)).Value
End With
On Error GoTo 0
End Sub
Private Sub ComboBox2_Change()
Application.ScreenUpdating = False
ComboBox3.Clear
valor = ComboBox2.Value
Hoja2.Select 'línea agregada
Set busca = ActiveSheet.Range("A5:D5").Find(valor, LookIn:=xlValues, LookAt:=xlWhole)
If Not busca Is Nothing Then
busca.Select
ActiveCell.Offset(1, 0).Select
Do While ActiveCell.Value <> ""
ComboBox3.AddItem ActiveCell.Value
ActiveCell.Offset(1, 0).Select
Loop
End If
Hoja1.Select 'línea agregada
End Sub
Private Sub BUSCAR_Click()
Application.ScreenUpdating = False
Sheets("hoja1").Select
If TextBox1 = "" Then
MsgBox "Coloca algun dato para buscar", vbOKOnly + vbInformation, "AVISO"
TextBox1.SetFocus
Exit Sub
End If
Set rango = Range("A:A").Find(What:=TextBox1, _
LookAt:=xlWhole, LookIn:=xlValues)
If rango Is Nothing Then
MsgBox "El dato no fue encontrado", vbOKOnly + vbInformation, "AVISO"
TextBox1 = "": TextBox1.SetFocus
Exit Sub
Else
TextBox2 = Range("B" & rango.Row)
TextBox3 = Range("C" & rango.Row)
ComboBox1 = Range("D" & rango.Row)
ComboBox2 = Range("E" & rango.Row)
ComboBox3 = Range("F" & rango.Row)
End If
End Sub
Private Sub ACTUALIZAR_Click()
Sheets("hoja1").Select
Dim ctr As Control
If rango Is Nothing Then
MsgBox "Aun no buscas ningun dato", vbOKOnly + vbInformation, "AVISO"
TextBox1.SetFocus
Exit Sub
End If
If TextBox2 = "" Or TextBox3 = "" Then
MsgBox "No dejes ningun campo en blanco", vbOKOnly + vbInformation, "AVISO"
Exit Sub
End If
Range("A" & rango.Row) = TextBox1
Range("B" & rango.Row) = TextBox2
Range("C" & rango.Row) = TextBox3
Range("D" & rango.Row) = ComboBox1
Range("E" & rango.Row) = ComboBox2
Range("F" & rango.Row) = ComboBox3
For Each ctr In Me.Controls
If TypeOf ctr Is MSForms.TextBox Then
ctr = ""
End If
If TypeOf ctr Is MSForms.ComboBox Then
ctr = ""
End If
Next ctr
TextBox1.SetFocus
Set ctr = Nothing
Set rango = Nothing
End Sub
Private Sub UserForm_Activate()
Application.ScreenUpdating = False
Hoja2.Select
Range("a1").Select
Do While ActiveCell <> Empty
ComboBox1.AddItem ActiveCell.Value
ActiveCell.Offset(0, 1).Select
Loop
End Sub

Añade tu respuesta

Haz clic para o

Más respuestas relacionadas