Buscar numero de factura para que no se repita

Nuevamente solicito su ayuda

En el ingreso de esta factura me envía un mensaje indicando que la factura ya fue ingresada pero es posible que 2 proveedores puedan tener la misma serie de documentos mi pregunta como puedo hacer para que el al ingresar la primero busque al proveedor y luego el documento y si se repite recién me envié el mensaje porque como le repito el numero del documento puede ser igual con 2 proveedores

Gracias por la atención prestada

1 Respuesta

Respuesta
1

Puedes poner el código que estás utilizando para buscar y completarlo con la búsqueda de proveedor.

hola Dante

adjunto lo solicitado

en el CommandButton3 esta al ingresar y busca si el numero esta repetido y se repite elimina la línea y genera una nueva 

Private Sub CommandButton3_Click()
'Hoja4.Activate
On Error Resume Next
Me.TextBox1.Text = Format(CInt(TextBox1.Text), "0000000")
'Me.txtNoFactura.Text = Format(CInt(txtNoFactura.Text), "0000000")
Err.Clear
If Trim(Me.TextBox1.Text) = "" Or Trim(Me.TextBox1.Text) = " " Then MsgBox ("Ingresar Nro Factura!!"): Exit Sub
Err.Clear
On Error Resume Next
Hoja4.Activate
ultm = Range("f65536").End(xlUp).Row
primm = Range("f1").Row
i = primm
Do Until Cells(i, 6) = Me.TextBox1.Text
If i <= ultm Then
i = i + 1
Else
Exit Do
End If
Loop
Cells(i, 6).Activate
If ActiveCell.Value = Trim(Me.TextBox1.Text) Then
 If MsgBox("La FT ya existe Desea Eliminar y Volver ha Generar", vbQuestion + vbYesNo) = vbYes Then
       buscarftrow
       Else
       TextBox1.Text = " "
       Exit Sub
       End If
Else
ActiveCell.Select
End If
Set h1 = Worksheets("INGRESOS")
u = h1.Range("c" & Rows.Count).End(xlUp).Row + 1
For i = 0 To ListBox6.ListCount - 1
        h1.Cells(u, "E") = ListBox4.List(i)   'Cantidad
        'h1.Cells(u, "C") = ListBox2.List(i)   'Unidad
        h1.Cells(u, "c") = ListBox6.List(i)   'Descripción
        h1.Cells(u, "F") = TextBox1           'Factura
        h1.Cells(u, "G") = ListBox7.List(i)   'Precio
        h1.Cells(u, "B") = ListBox3.List(i)  'codigo
        h1.Cells(u, "a") = TextBox4.Text    'proveedor
        h1.Cells(u, "I") = ComboBox1.Text   'almacen
        h1.Cells(u, "h") = DTPicker1      'fecha
        u = u + 1
Next
linea
limpiarTodo
Unload Me
Worksheets.Save
Private Sub buscarftrow()
'Sheets("ingresos").Select
Dim primera As Variant
Dim ultima As Variant
On Error Resume Next
Hoja4.Activate
ultima = Range("f65536").End(xlUp).Row
primera = Range("f1").Row
i = ultima
Do Until Cells(i, 6) = TextBox1.Text
If i > 1 Then
i = i - 1
Else
Exit Do
End If
Loop
If i <> 1 Then
Cells(i, 6).Select
ULTIMAENC = Cells(i, 6).Row
Else
End If
ult = Range("f65536").End(xlUp).Row
prim = Range("f1").Row
i = prim
Do Until Cells(i, 6) = TextBox1.Text
If i < ult Then
i = i + 1
Else
Exit Do
End If
Loop
If i <> ult Then
Cells(i, 6).Select
PRIMENC = Cells(i, 6).Row
End If
Range("A" & PRIMENC, "A" & ULTIMAENC).Select
Selection.EntireRow.Delete
End Sub

saludos

Robert

Te regreso la macro actualizada, supongo que el proveedor está en el textbox4.

Ya no es necesaria tu macro buscarftrow

Private Sub CommandButton3_Click()
'Act.Por.Dante Amor
    'Hoja4.Activate
    On Error Resume Next
    Me.TextBox1.Text = Format(CInt(TextBox1.Text), "0000000")
    'Me.txtNoFactura.Text = Format(CInt(txtNoFactura.Text), "0000000")
    Err.Clear
    If Trim(Me.TextBox1.Text) = "" Or Trim(Me.TextBox1.Text) = " " Then MsgBox ("Ingresar Nro Factura!!"): Exit Sub
    Err.Clear
    On Error Resume Next
    Hoja4.Activate
    '
    For i = 1 To Range("F" & Rows.Count).End(xlUp).Row
        If Cells(i, "F") = TextBox1 And Cells(i, "A") = TextBox4 Then
            If MsgBox("La FT ya existe Desea Eliminar y Volver ha Generar", _
                vbQuestion + vbYesNo) = vbYes Then
                Rows(i).Delete
            Else
                TextBox1.Text = " "
                Exit Sub
            End If
        End If
    Next
    '
    Set h1 = Worksheets("INGRESOS")
    u = h1.Range("c" & Rows.Count).End(xlUp).Row + 1
    For i = 0 To ListBox6.ListCount - 1
        h1.Cells(u, "E") = ListBox4.List(i)     'Cantidad
        'h1.Cells(u, "C") = ListBox2.List(i)   'Unidad
        h1.Cells(u, "c") = ListBox6.List(i)     'Descripción
        h1.Cells(u, "F") = TextBox1             'Factura
        h1.Cells(u, "G") = ListBox7.List(i)     'Precio
        h1.Cells(u, "B") = ListBox3.List(i)     'codigo
        h1.Cells(u, "a") = TextBox4.Text        'proveedor
        h1.Cells(u, "I") = ComboBox1.Text       'almacen
        h1.Cells(u, "h") = DTPicker1            'fecha
        u = u + 1
    Next
    Linea
    Limpiartodo
    Unload Me
    Worksheets. Save
End Sub

Saludos.Dante Amor

Recuerda valorar la respuesta.

hola Dante

tu código de buscar con la dos variables esta perfecto

pero hay un tema el buscarftrow eliminaba todos los valores repetidos y agregaba los nuevos pero  ahora elimina solo una columna de 1 en 1 no elimina toda la información repetida

el código que adjuntaste hace lo mismo elimina 1 por 1 el registro y a veces no elimina toda la información repetida

Rows(i).Delete

saludos

Robert

Cambia esto:

For i = 1 To Range("F" & Rows.Count).End(xlUp).Row        If Cells(i, "F") = TextBox1 And Cells(i, "A") = TextBox4 Then            If MsgBox("La FT ya existe Desea Eliminar y Volver ha Generar", _                vbQuestion + vbYesNo) = vbYes Then                Rows(i).Delete            Else                TextBox1.Text = " "                Exit Sub            End If        End If    Next

Por esto:

    eliminar = False
    For i = Range("F" & Rows.Count).End(xlUp).Row To 1 Step -1
        If Cells(i, "F") = TextBox1 And Cells(i, "A") = TextBox4 Then
            If eliminar = False Then
                If MsgBox("La FT ya existe Desea Eliminar y Volver ha Generar", _
                    vbQuestion + vbYesNo) = vbYes Then
                    eliminar = True
                Else
                    TextBox1.Text = " "
                    Exit Sub
                End If
            End If
            Rows(i).Delete
        End If
    Next

Añade tu respuesta

Haz clic para o

Más respuestas relacionadas