0% encontró este documento útil (0 votos)
108 vistas8 páginas

C ODIGOS

no sirven no lo usen

Cargado por

dpirias09
Derechos de autor
© © All Rights Reserved
Nos tomamos en serio los derechos de los contenidos. Si sospechas que se trata de tu contenido, reclámalo aquí.
Formatos disponibles
Descarga como DOCX, PDF, TXT o lee en línea desde Scribd
0% encontró este documento útil (0 votos)
108 vistas8 páginas

C ODIGOS

no sirven no lo usen

Cargado por

dpirias09
Derechos de autor
© © All Rights Reserved
Nos tomamos en serio los derechos de los contenidos. Si sospechas que se trata de tu contenido, reclámalo aquí.
Formatos disponibles
Descarga como DOCX, PDF, TXT o lee en línea desde Scribd

Private Sub BT_Buscar_Click()

Dim ULFILA As Long

Dim FILA As Long

' Limpiar el ListBox antes de agregar nuevos elementos

[Link]

' Verificar que la hoja "Inventario" existe

If Not SheetExists("Inventario") Then

MsgBox "La hoja 'Inventario' no existe.", vbCritical

Exit Sub

End If

' Obtener la última fila con datos en la columna B de la hoja "Inventario"

ULFILA = Sheets("Inventario").Range("B" & [Link]).End(xlUp).Row

' Recorrer desde la fila 2 hasta la última fila con datos

For FILA = 2 To ULFILA

' Verificar si el valor en la columna B contiene el valor buscado en el TextBox

If InStr(1, Sheets("Inventario").Cells(FILA, 2).Value, [Link], vbTextCompare) > 0


Then

' Agregar el primer valor (columna A) al ListBox

[Link] Sheets("Inventario").Cells(FILA, 1).Value

' Agregar los valores restantes a las columnas del ListBox

[Link]([Link] - 1, 0) = Sheets("Inventario").Cells(FILA, 2).Value

[Link]([Link] - 1, 1) = Sheets("Inventario").Cells(FILA, 3).Value

[Link]([Link] - 1, 2) = Sheets("Inventario").Cells(FILA, 4).Value

[Link]([Link] - 1, 3) = Sheets("Inventario").Cells(FILA, 5).Value


[Link]([Link] - 1, 4) = Sheets("Inventario").Cells(FILA, 6).Value

[Link]([Link] - 1, 5) = Sheets("Inventario").Cells(FILA, 7).Value

[Link]([Link] - 1, 6) = Sheets("Inventario").Cells(FILA, 8).Value

[Link]([Link] - 1, 7) = Sheets("Inventario").Cells(FILA, 9).Value

[Link]([Link] - 1, 8) = Sheets("Inventario").Cells(FILA, 10).Value

[Link]([Link] - 1, 9) = Sheets("Inventario").Cells(FILA, 11).Value

End If

Next FILA

End Sub

' Función para verificar si una hoja existe en el workbook

Function SheetExists(sheetName As String) As Boolean

Dim ws As Worksheet

SheetExists = False

For Each ws In [Link]

If [Link] = sheetName Then

SheetExists = True

Exit Function

End If

Next ws

End Function

Private Sub BT_Editar_Click()

Dim FILA As Object

Dim LINEA As Variant

Dim ValorBuscado As Variant


If [Link] = -1 Then

MsgBox " SELECCIONE EL PRODUCTO A EDITAR"

Else

[Link] = Me.Lista2

ValorBuscado = [Link]

Set FILA = Sheets("Inventario").Range("B:B").Find(ValorBuscado, LookAt:=xlWhole)

LINEA = [Link]

[Link] = Range("H" & LINEA).Value

[Link] = Range("A" & LINEA).Value

[Link] = Range("C" & LINEA).Value

[Link] = Range("F" & LINEA).Value

[Link] = Range("D" & LINEA).Value

[Link] = Range("E" & LINEA).Value

[Link] = Range("G" & LINEA).Value

End If

End Sub
Private Sub BT_EditarProducto_Click()

Dim FILA As Range

Dim LINEA As Long

Dim ValorBuscado As String

' Verificar si hay un elemento seleccionado en el ListBox

If [Link] = -1 Then

MsgBox "Debe seleccionar un producto para editar.", vbExclamation

Exit Sub

End If

' Obtener el valor del producto seleccionado en el ListBox

ValorBuscado = [Link]

' Buscar el valor en la columna B de la hoja "Inventario"

Set FILA = Sheets("Inventario").Range("B:B").Find(What:=ValorBuscado, LookAt:=xlWhole)

' Verificar si se encontró el valor

If FILA Is Nothing Then

MsgBox "El producto no se encontró en el inventario.", vbExclamation

Exit Sub

End If

' Obtener la fila del valor encontrado

LINEA = [Link]

' Actualizar los valores en la hoja "Inventario"


With Sheets("Inventario")

.Range("A" & LINEA).Value = [Link]

.Range("B" & LINEA).Value = [Link]

.Range("C" & LINEA).Value = [Link]

.Range("D" & LINEA).Value = [Link]

.Range("E" & LINEA).Value = [Link]

.Range("F" & LINEA).Value = [Link]

.Range("G" & LINEA).Value = [Link]

.Range("H" & LINEA).Value = [Link]

End With

' Limpiar los campos del formulario

[Link] = ""

[Link] = ""

[Link] = ""

[Link] = ""

[Link] = ""

[Link] = ""

[Link] = ""

[Link] = ""

' Mostrar mensaje de éxito

MsgBox "El producto fue modificado con éxito.", vbInformation

' Actualizar el ListBox

Call BT_Buscar_Click ' Asumiendo que BT_Buscar_Click recarga el ListBox


End Sub

Private Sub Bt_Eliminar_Click()

Dim FILA As Range

Dim LINEA As Long

Dim IdBuscado As String

' Verificar si se ha seleccionado un elemento en el ListBox

If [Link] = -1 Then

MsgBox "SELECCIONE EL DATO A ELIMINAR", vbExclamation

Exit Sub

End If

' Obtener el valor seleccionado en el ListBox

IdBuscado = [Link]

' Buscar el valor en la columna B de la hoja "Inventario"

Set FILA = Sheets("Inventario").Range("B:B").Find(What:=IdBuscado, LookAt:=xlWhole)

' Verificar si se encontró el valor

If FILA Is Nothing Then

MsgBox "El producto no se encontró en el inventario.", vbExclamation

Exit Sub

End If

' Obtener la fila del valor encontrado

LINEA = [Link]
' Eliminar la fila completa

Sheets("Inventario").Rows(LINEA).Delete

' Mostrar mensaje de éxito

MsgBox "EL PRODUCTO FUE ELIMINADO", vbInformation

' Limpiar el ListBox y recargar los datos

[Link]

Call BT_Buscar_Click ' Asumiendo que BT_Buscar_Click recarga el ListBox

End Sub

Private Sub BT_GUARDAR_Click()

' Verificar si algún campo está vacío

If [Link] = "" Or _

[Link] = "" Or _

[Link] = "" Or _

[Link] = "" Or _

[Link] = "" Or _

[Link] = "" Or _

[Link] = "" Or _

[Link] = "" Then

' Mostrar mensaje de advertencia


MsgBox "NO HAY DATOS PARA GUARDAR", vbExclamation

Exit Sub

End If

' Insertar una nueva fila en la hoja "Inventario" y copiar el formato

Sheets("Inventario").Range("A2").[Link] , CopyOrigin:=xlFormatFromRightOrBelow

' Asignar valores a la nueva fila

With Sheets("Inventario")

.Range("A2").Value = [Link]

.Range("B2").Value = [Link]

.Range("C2").Value = [Link]

.Range("D2").Value = [Link]

.[Link]

.Range("F2").Value = [Link]

.Range("G2").Value = [Link]

.Range("H2").Value = [Link]

End With

' Actualizar el ListBox

[Link]

Call BT_Buscar_Click ' Asumiendo que BT_Buscar_Click recarga el ListBox

Me.

[Link] = ""

[Link] = ""

[Link] = ""

[Link] = ""

También podría gustarte