Está en la página 1de 6

TALLER DE BUSQUEDA EN FORMULARIOS.

1. Digitar estos datos en la hoja(Hoja1):


2. Hacer el siguiente formulario:

3. Hacer la siguiente macro en el TextBox1:

Private Sub TextBox1_AfterUpdate()

Sheets("Hoja1").Select

filalibre = Range("A2").End(xlDown).Offset(1, 0).Row

control = 0

dato = TextBox1

rango = "A2:A" & filalibre

Set midato = ActiveSheet.Range(rango).Find(dato, LookIn:=xlValues, LookAt:=xlWhole)

If (midato) Is Nothing Then

'No lo encontro

MsgBox "LOS DATOS NO SE ENCONTRARON, SE PROCEDE A CARGAR UN REGISTRO NUEVO:::"

Else

'Encontro el dato

ubica = midato.Address(False, False)

TextBox2.Value = Range(ubica).Offset(0, 1).Value

TextBox3.Value = Range(ubica).Offset(0, 2).Value

control = 1

MsgBox "DATOS CARGADOS CON EXITO:::"

End If

Set midato = Nothing

End Sub
4. Hacer el siguiente programa en el CommandButtom1:

Public ubica As String

Public control As Integer

Public filalibre As Integer

Private Sub CommandButton1_Click()

Sheets("Hoja1").Select

If control > 0 Then

'Actualizar datos

Range(ubica).Value = TextBox1

Range(ubica).Offset(0, 1).Value = TextBox2

Range(ubica).Offset(0, 2).Value = Val(TextBox3)

control = 0

Else

'Crear datos

Cells(filalibre, 1).Value = TextBox1

Cells(filalibre, 2).Value = TextBox2

Cells(filalibre, 3).Value = Val(TextBox3)

End If

TextBox1 = Empty

TextBox2 = Empty

TextBox3 = Empty

TextBox1.SetFocus

End Sub
5. Hacer el siguiente programa en el CommandButtom2:

Private Sub CommandButton2_Click()

TextBox1 = Empty

TextBox2 = Empty

TextBox3 = Empty

TextBox1.SetFocus

End Sub
6. Hacer la siguiente Macro en el CommandButtom3:

Private Sub CommandButton3_Click()

End

End Sub
7. Asignar la siguiente macro a este botón:

Sub forma()

Load UserForm1

UserForm1.Show

End Sub

También podría gustarte