You are on page 1of 5

Codificación de Formulario Búsqueda e ingreso de datos en Excel

Option Explicit

Dim id_semestre As Integer

Dim id_grupo As Integer

Dim id_alumno As Integer

Private Sub Btningresar_Click()

Dim fila As Integer

fila = 1

While Cells(fila, 1) <> ""

fila = fila + 1

Wend

Cells(fila, 1) = txtNombre.Value

Cells(fila, 2) = txtpaterno.Value

Cells(fila, 3) = txtcontrol.Value

Cells(fila, 4) = txtEmail.Value

txtNombre.Value = Empty

txtpaterno.Value = Empty

txtcontrol.Value = Empty

txtEmail.Value = Empty

cbo_semestre.Value = Empty

cbo_grupo.Value = Empty

cbo_alumno.Value = Empty

cbo_semestre.SetFocus

End Sub
Private Sub cbo_semestre_Change()

Dim fila As Integer

Dim Final As Integer

cbo_grupo.Clear

With Hoja3 ' Tabla Departamentos

id_semestre = cbo_semestre.ListIndex + 1

Final = .Cells(1, 1).End(xlDown).Row

For fila = 2 To Final

If Mid(.Cells(fila, 1), 1, 1) = id_semestre Then

cbo_grupo.AddItem (.Cells(fila, 2))

End If

Next

End With

End Sub

Private Sub cbo_grupo_Change()

Dim fila As Integer

Dim Final As Integer

cbo_alumno.Clear

Call LimpiarTextBoxes
With Hoja4 'Tabla Alumnos

id_grupo = cbo_grupo.ListIndex + 1

Final = .Cells(1, 1).End(xlDown).Row

For fila = 2 To Final

If Mid(.Cells(fila, 1), 1, 1) = id_semestre And _

Mid(.Cells(fila, 1), 2, 1) = id_grupo Then

cbo_alumno.AddItem (.Cells(fila, 2))

End If

Next

End With

End Sub

Private Sub cbo_alumno_Change()

Dim fila As Integer

Dim Final As Integer

Call LimpiarTextBoxes

With Hoja4 'Tabla Alumnos

id_alumno = cbo_alumno.ListIndex + 1

Final = .Cells(1, 1).End(xlDown).Row

For fila = 2 To Final

If Mid(.Cells(fila, 1), 1, 1) = id_semestre And _

Mid(.Cells(fila, 1), 2, 1) = id_grupo And _

Mid(.Cells(fila, 1), 3, 2) = id_alumno Then


txtNombre = .Cells(fila, 2)

txtcontrol = .Cells(fila, 3)

txtpaterno = .Cells(fila, 4)

txtEmail = .Cells(fila, 5)

End If

Next

End With

End Sub

Private Sub UserForm_Initialize()

Dim fila As Integer

Dim Final As Integer

With Hoja2 'Tabla Semestre

Final = .Cells(1, 1).End(xlDown).Row

For fila = 2 To Final

If .Cells(fila, 1) <> "" Then

cbo_semestre.AddItem (.Cells(fila, 2))

End If

Next

End With

End Sub

Sub LimpiarTextBoxes()

txtNombre = Empty

txtcontrol = Empty
txtpaterno = Empty

txtEmail = Empty

End Sub

Private Sub btncerrar_Click()

Unload Me

End Sub

You might also like