0% found this document useful (0 votes)
62 views4 pages

Codigos Programa Pruebita

The document contains code for a userform in VBA that allows users to search for, add, modify, and delete student records stored in a worksheet. The userform contains controls like text boxes and combo boxes. Buttons trigger macros to perform the CRUD functions on the worksheet using cell references and the VLookup function. Validation and error handling is included.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
62 views4 pages

Codigos Programa Pruebita

The document contains code for a userform in VBA that allows users to search for, add, modify, and delete student records stored in a worksheet. The userform contains controls like text boxes and combo boxes. Buttons trigger macros to perform the CRUD functions on the worksheet using cell references and the VLookup function. Validation and error handling is included.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 4

Option Explicit

Option Private Module

Public Function nReg(Hoja As Worksheet, nFila As Long, nColumna As Integer)

Do Until IsEmpty(Hoja.Cells(nFila, nColumna))

nFila = nFila + 1

Loop

nReg = nFila

End Function

Option Explicit

Private Sub CmdBuscar_Click()

On Error Resume Next

Me.TxtDni.Text = Application.WorksheetFunction.VLookup(Me.TxtCodigo.Text,
Hoja1.Range("A:F"), 2, 0)

Me.TxtApellidos.Text = Application.WorksheetFunction.VLookup(Me.TxtCodigo.Text,
Hoja1.Range("A:F"), 3, 0)

Me.TxtNombres.Text = Application.WorksheetFunction.VLookup(Me.TxtCodigo.Text,
Hoja1.Range("A:F"), 4, 0)

Me.CmbGrado.Text = Application.WorksheetFunction.VLookup(Me.TxtCodigo.Text,
Hoja1.Range("A:F"), 5, 0)

Me.CmbSeccion.Text = Application.WorksheetFunction.VLookup(Me.TxtCodigo.Text,
Hoja1.Range("A:F"), 6, 0)

Me.TxtCodigo.Enabled = False

End Sub

Private Sub CmdEliminar_Click()

Dim uFila, X As Long


uFila = nReg(Hoja1, 4, 1) - 1

For X = 4 To uFila

If Me.TxtCodigo.Text = Hoja1.Cells(X, 1) Then

Hoja1.Cells(X, 1).EntireRow.Delete

Exit For

End If

Next X

Call Limpiar

Me.TxtCodigo.Enabled = True

End Sub

Private Sub CmdGuardar_Click()

Dim uFila, X As Long

uFila = nReg(Hoja1, 4, 1)

Hoja1.Cells(uFila, 1) = Me.TxtCodigo.Text

Hoja1.Cells(uFila, 2) = Me.TxtDni.Text

Hoja1.Cells(uFila, 3) = Me.TxtApellidos.Text

Hoja1.Cells(uFila, 4) = Me.TxtNombres.Text

Hoja1.Cells(uFila, 5) = Me.CmbGrado.Text

Hoja1.Cells(uFila, 6) = Me.CmbSeccion.Text

Call Limpiar

Me.TxtCodigo.SetFocus
MsgBox ("Datos guardados con éxito"), vbInformation, "Excel Cuantico"

End Sub

Sub Limpiar()

Me.TxtCodigo.Text = Empty

Me.TxtDni.Text = Empty

Me.TxtApellidos.Text = Empty

Me.TxtNombres.Text = Empty

Me.CmbGrado.Text = Empty

Me.CmbSeccion.Text = Empty

End Sub

Private Sub CmdModificar_Click()

Dim uFila, X As Long

uFila = nReg(Hoja1, 4, 1) - 1

For X = 4 To uFila

If Me.TxtCodigo.Text = Hoja1.Cells(X, 1) Then

Hoja1.Cells(X, 2) = Me.TxtDni.Text

Hoja1.Cells(X, 3) = Me.TxtApellidos.Text

Hoja1.Cells(X, 4) = Me.TxtNombres.Text

Hoja1.Cells(X, 5) = Me.CmbGrado.Text

Hoja1.Cells(X, 6) = Me.CmbSeccion.Text

Exit For

End If

Next X

Call Limpiar

Me.TxtCodigo.Enabled = True
End Sub

Private Sub CmdSalir_Click()

Unload Me

End Sub

Private Sub UserForm_Initialize()

With Me.CmbGrado

.AddItem "1º", 0

.AddItem "2º", 1

.AddItem "3º", 2

.AddItem "4º", 3

.AddItem "5º", 4

.AddItem "6º", 5

End With

With Me.CmbSeccion

.AddItem "A", 0

.AddItem "B", 1

.AddItem "C", 2

.AddItem "D", 3

.AddItem "E", 4

End With

End Sub

You might also like