Tengo un Problema con fórmula, tengo un ComboBox1 que al elegir debe cargarme información en los textbox

Tengo un ComboBox precargado con información y al elegir un código me debería cargar en el textbox1 información de la hoja1, textbox2 información de la hoja6 pero no las carga, aquí el código, gracias.

Private Sub ComboBox1_Click()
Dim i As Integer
Dim j As Integer
Dim final As Integer
Dim FINAL2 As Integer

For i = 2 To 1000
If Hoja1.Cells(i, 1) = "" Then
final = i - 1
Exit For
End If
Next

For i = 2 To 1000
If Hoja5.Cells(i, 1) = "" Then
FINAL2 = i - 1
Exit For
End If
Next

For i = 2 To final
If ComboBox1 = Hoja1.Cells(i, 1) Then
TextBox1 = Hoja1.Cells(i, 2)
Exit For
End If
Next

For j = 1 To FINAL2
If ComboBox1 = Hoja6.Cells(j, 1) Then
TextBox2 = Hoja6.Cells(j, 3)
Exit For
End If
Next

End Sub

Private Sub ComboBox1_Enter()
Dim i As Integer
Dim j As Integer
Dim H As Integer
Dim final As Integer
Dim tareas As String

ComboBox1.BackColor = &H80000005

For i = 1 To ComboBox1.ListCount
ComboBox1.RemoveItem 0
Next i
For j = 2 To 1000
If Hoja1.Cells(j, 1) = "" Then
final = j - 1
Exit For
End If
Next
For H = 2 To final
tareas = Hoja1.Cells(H, 1)
ComboBox1.AddItem (tareas)
Next
'End If
End Sub

Private Sub CommandButton1_Click()
Dim validar As Boolean
Dim validarfecha As Boolean
If TextBox1 = "" Then
UserForm4.Show
Exit Sub
End If

If TextBox3 = "" Then
UserForm5.Show
Exit Sub
End If

If TextBox4 = "" Then
UserForm6.Show
Exit Sub
End If

If TextBox5 = "" Then
UserForm7.Show
Exit Sub
End If

validar = IsNumeric(TextBox3.Value)
If validar = False Then
UserForm8.Show
TextBox3.BackColor = &HFF00&
Exit Sub
End If

validarfecha = IsDate(TextBox5.Value)
If validarfecha = False Then
UserForm9.Show

1 Respuesta

Respuesta
2

El código se ve bien, tal vez haya que hacer algunos ajustes.

Pero si no está encontrando el valor, puede significar que en la hoja tienes números y en el combo tienes texto, eso puede ser, por eso no lo encuentra, o tienes fechas o en el dato tienes espacios adicionales.

Tendría que revisar tu archivo para ver cuál es el problema. Envíame tu archivo.

Mi correo [email protected]

En el asunto del correo escribe tu nombre de usuario “Eduar Esparragoza

Dante ya te envié el archivo a tu correo

Te anexo el código actualizado

Private Sub ComboBox1_Change()
'Por.Dante Amor
    TextBox1.Value = ""
    TextBox2.Value = ""
    If ComboBox1.Value = "" Or ComboBox1.ListIndex = -1 Then
        Exit Sub
    End If
    '
    If IsNumeric(ComboBox1.Value) Then valor = Val(ComboBox1.Value) Else valor = ComboBox1.Value
    Set b = Hoja1.Columns("A").Find(valor, lookat:=xlWhole, LookIn:=xlValues)
    If Not b Is Nothing Then
        TextBox1 = Hoja1.Cells(b.Row, 2)
    End If
    Set b = Hoja6.Columns("A").Find(ComboBox1.Value)
    If Not b Is Nothing Then
        TextBox2 = Hoja6.Cells(b.Row, 3)
    End If
End Sub
'
Private Sub CommandButton2_Click()
    Unload Me
End Sub
'
Private Sub UserForm_Activate()
    'Para cargar los códigos de la hoja1 en el combo
    i = 2
    Do While Hoja1.Cells(i, "A") <> ""
        ComboBox1.AddItem Hoja1.Cells(i, "A")
        i = i + 1
    Loop
End Sub
'

.

.

Añade tu respuesta

Haz clic para o

Más respuestas relacionadas