0% found this document useful (0 votes)
24 views6 pages

Private Sub BTN

The document contains code for a userform in VBA that allows adding, modifying, and searching for book records in a worksheet. It includes procedures for clicking buttons to add new records by transferring textbox values to cells, clear the textboxes, modify an existing record found by code, and search the worksheet to populate a listbox. Additional code defines clicking behaviors for the listbox to load the selected record into the textboxes.
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)
24 views6 pages

Private Sub BTN

The document contains code for a userform in VBA that allows adding, modifying, and searching for book records in a worksheet. It includes procedures for clicking buttons to add new records by transferring textbox values to cells, clear the textboxes, modify an existing record found by code, and search the worksheet to populate a listbox. Additional code defines clicking behaviors for the listbox to load the selected record into the textboxes.
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/ 6

Private Sub btn_agregar_Click()

Dim codigo As Range

Set codigo = Worksheets("Hoja1").Range("D5")

codigo.Value = txt_codigo.Text

Dim titulo As Range

Set titulo = Worksheets("Hoja1").Range("E5")

titulo.Value = txt_titulo.Text

Dim autor As Range

Set autor = Worksheets("Hoja1").Range("F5")

autor.Value = txt_autor.Text

Dim resumen As Range

Set resumen = Worksheets("Hoja1").Range("G5")

resumen.Value = txt_resumen.Text

Dim stock As Range

Set stock = Worksheets("Hoja1").Range("H5")

stock.Value = txt_stock.Text

Dim cantidad As Range

Set cantidad = Worksheets("Hoja1").Range("I5")

cantidad.Value = txt_cantidad.Text

stock.EntireRow.Insert

End Sub
888888888888888888888888888888888888888888888888888888888888888888888888888888

Private Sub btn_limpiar_Click()

txt_codigo.Text = ""

txt_titulo.Text = ""

txt_autor.Text = ""

txt_resumen.Text = ""

txt_stock.Text = ""

txt_cantidad.Text = ""

End Sub

8888888888888888888888888888888888888888888888888888888888888888888888888888

Private Sub btn_modificar_Click()

Dim fila As Object

Dim linea As Integer

valor_buscado = Me.txt_codigo

Set fila = Sheets("Hoja1").Range("D:D").Find(valor_buscado, lookat:=xlWhole)

linea = fila.Row

Range("E" & linea).Value = Me.txt_titulo.Value

Range("F" & linea).Value = Me.txt_autor.Value

Range("G" & linea).Value = Me.txt_resumen.Value

Range("H" & linea).Value = Me.txt_stock.Value

Range("I" & linea).Value = Me.txt_cantidad.Value


End Sub

888888888888888888888888888888888888888888888888888888888888888888888

Private Sub CommandButton1_Click()

Dim i As Long

ListBox1.Clear

'llenar titulos de las columnas

ListBox1.AddItem

For a = 4 To 9

ListBox1.List(0, a - 4) = Hoja1.Cells(4, a)

Next a

ListBox1.ColumnHeads = False

For i = 6 To Hoja1.Range("D1000000").End(xlUp).Offset(1, 0).Row

For j = 4 To 9

h = Application.WorksheetFunction.CountIf(Hoja1.Range("D" & 2, "I" & i), Hoja1.Cells(i, j))


If h = 1 And LCase(Hoja1.Cells(i, j)) = LCase(Me.TextBox1) Or h = 1 And Hoja1.Cells(i, j) =
Val(Me.TextBox1) Then

ListBox1.AddItem

For X = 4 To 9

ListBox1.List(ListBox1.ListCount - 1, X - 4) = Hoja1.Cells(i, X)

Next X

End If

Next j

Next i

End Sub

8888888888888888888888888888888888888888888888888888888888888888888888888888888

Private Sub ListBox1_Click()

Dim codigo As Integer

txt_codigo = ListBox1.List(ListBox1.ListIndex, 0)

txt_titulo = ListBox1.List(ListBox1.ListIndex, 1)

txt_autor = ListBox1.List(ListBox1.ListIndex, 2)

txt_resumen = ListBox1.List(ListBox1.ListIndex, 3)

txt_stock = ListBox1.List(ListBox1.ListIndex, 4)

txt_cantidad = ListBox1.List(ListBox1.ListIndex, 5)

Me.txt_codigo.Value = txt_codigo
End Sub

}888888888888888888888888888888888888888888888888888888888888888888888888888888

funcion de hoja de trabajo


cuenta
rango
888888888888888888888888888888

Private Sub LISTA_Click()

Dim codigo As Integer

codigo = LISTA.List(LISTA.ListIndex, 0)

titulo = LISTA.List(LISTA.ListIndex, 1)

autor = LISTA.List(LISTA.ListIndex, 2)

resumen = LISTA.List(LISTA.ListIndex, 3)

stock = LISTA.List(LISTA.ListIndex, 4)

cantidad = LISTA.List(LISTA.ListIndex, 5)

Me.txt_codigo.Value = codigo

Me.txt_titulo.Value = titulo

Me.txt_autor.Value = autor

Me.txt_resumen.Value = resumen

Me.txt_stock.Value = stock

Me.txt_cantidad.Value = cantidad
End Sub

88888888888888888888888888888888888888888888888888888888888888

Private Sub UserForm_Initialize()

cbx_autor.List = Worksheets("autor").Range("A2:A6").Value

End Sub

You might also like