mercredi 16 mai 2018

EXCEL VBA , Allow only if condition verifies

So, I want to make a condition that if an item doesn't have an entry register in the warehouse, it must be impossible for him to leave as it never checked in. I manage to put a stock control where users can only move to certain quantities but I have not yet managed to get the check in and out control statement.

last = Application.ThisWorkbook.Worksheets("Registos").Range("A65536").End(xlUp).Row
For i = 1 To last
    REFERENCIA = Application.ThisWorkbook.Worksheets("Registos").Cells(i, 8)
    ENTRADAeSAIDA = Application.ThisWorkbook.Worksheets("Registos").Cells(i, 12)
    CC = Application.ThisWorkbook.Worksheets("Registos").Cells(i, 6)


        If REFERENCIA = registos.TextBox1 And registos.ComboBox1 = "SAÍDA" Then
            Worksheets("registos").Select
            ActiveSheet.ListObjects("Tabela1").Range.AutoFilter Field:=8, Criteria1:= _
            registos.TextBox1.Text                                                        'Filtrar referência

            ActiveSheet.ListObjects("Tabela1").Range.AutoFilter Field:=6, Criteria1:= _
            registos.Label11.Caption                                                      'Filtrar CC

            ActiveSheet.ListObjects("Tabela1").Range.AutoFilter Field:=12, Criteria1:= _
            "ENTRADA"                                                                     'Filtrar Entrada

            'Somar quantidades de peças de Entrada
            xty100 = ThisWorkbook.Worksheets("calculos").Range("A1")

            ActiveSheet.ListObjects("Tabela1").Range.AutoFilter Field:=12, Criteria1:= _
            "SAÍDA"                                                                       'Filtrar Saída

            'Somar quantidade de peças de saída
            xty101 = ThisWorkbook.Worksheets("calculos").Range("A1")

            sumfinal = xty100 - xty101                                                     'Calculo do Stock


            ThisWorkbook.Worksheets("calculos").Range("A20") = Format(registos.TextBox4, "@")
            xtybx4 = ThisWorkbook.Worksheets("calculos").Range("A20")

            If xtybx4 <= sumfinal Then
            GoTo salto_2
               Else
                MsgBox "Não é possível movimentar mais que o stock atual!Stock " & sumfinal & ""
                GoTo fim
            End If
        End If 
   Next i

Aucun commentaire:

Enregistrer un commentaire