Crear texbox

Hola, necesitaria crear un texbox en la hoja1 donde ingresar datos del tipo nombre,apellidos,etc, con un comandbotton donde al hacer click los datos ingresados se archivararan en la hoja2 consecutivamente y en la siguiente linea vacia.
Luego necesitaria crear otro donde al ingresar por ejemplo uno de los nombres archivados me saliesen todos los datos de ese nombre archivados en la hoja 2.

1 respuesta

Respuesta
1
Te comento lo que te paso. Está el libro con la hoja 1 donde hay 4 textbox (textbox1 para nombre, textbox2 para apellido1, textbox3 para apellido2 y textbox4 para teléfono). Aparte tenemos el commandbutton1 para agregar valores a la hoja2 que tengamos en ese momento en los textbox. Y por ultimo el control commandbutton2 y combobox1 que nos serviran para buscar en la hoja2 los registros coincidentes con los valores introducidos en los textbox. Si encuentra un solo registro lo mete a los textbox directamente, si encuentra varios los mete al combobox1 y cuando selecciones de el el que quieras te pasa esos datos a los textbox. Pega este codigo a la hoja donde tengas esos controles incrustados.
Private Sub ComboBox1_Change()
rellenar (ComboBox1.ListIndex + 1)
End Sub
Private Sub CommandButton1_Click()
Dim z As Integer
z = 1
While ThisWorkbook.Sheets(2).Cells(z, 1).Value <> ""
    z = z + 1
Wend
ThisWorkbook.Sheets(2).Cells(z, 1).Value = TextBox1.Text
ThisWorkbook.Sheets(2).Cells(z, 2).Value = TextBox2.Text
ThisWorkbook.Sheets(2).Cells(z, 3).Value = TextBox3.Text
ThisWorkbook.Sheets(2).Cells(z, 4).Value = TextBox4.Text
TextBox1.Text = ""
TextBox2.Text = ""
TextBox3.Text = ""
TextBox4.Text = ""
End Sub
Private Sub CommandButton2_Click()
While ComboBox1.ListCount > 0
    ComboBox1.RemoveItem (0)
Wend
Dim z As Integer
z = 1
While ThisWorkbook.Sheets(2).Cells(z, 1).Value <> ""
    If ThisWorkbook.Sheets(2).Cells(z, 1).Value = TextBox1.Text Or ThisWorkbook.Sheets(2).Cells(z, 2).Value = TextBox2.Text Or ThisWorkbook.Sheets(2).Cells(z, 3).Value = TextBox3.Text Or ThisWorkbook.Sheets(2).Cells(z, 4).Value = TextBox4.Text Then
        ComboBox1. AddItem (ThisWorkbook. Sheets(2).Cells(z, 1).Value & " " & ThisWorkbook. Sheets(2).Cells(z, 2).Value & " " & ThisWorkbook. Sheets(2).Cells(z, 3).Value & " " & ThisWorkbook. Sheets(2).Cells(z, 4). Value)
    End If
    z = z + 1
Wend
If ComboBox1.ListCount = 1 Then
    rellenar (1)
End If
End Sub
Sub rellenar(i As Integer)
Dim z As Integer
z = 1
Count = 0
While ThisWorkbook.Sheets(2).Cells(z, 1).Value <> ""
If ThisWorkbook.Sheets(2).Cells(z, 1).Value = TextBox1.Text Or ThisWorkbook.Sheets(2).Cells(z, 2).Value = TextBox2.Text Or ThisWorkbook.Sheets(2).Cells(z, 3).Value = TextBox3.Text Or ThisWorkbook.Sheets(2).Cells(z, 4).Value = TextBox4.Text Then
    Count = Count + 1
    If Count = i Then
        TextBox1.Text = ThisWorkbook.Sheets(2).Cells(z, 1).Value
        TextBox2.Text = ThisWorkbook.Sheets(2).Cells(z, 2).Value
        TextBox3.Text = ThisWorkbook.Sheets(2).Cells(z, 3).Value
        TextBox4.Text = ThisWorkbook.Sheets(2).Cells(z, 4).Value
    End If
End If
z = z + 1
Wend
End Sub

Añade tu respuesta

Haz clic para o

Más respuestas relacionadas