Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

160
Visualizações
Comparing two Sheets based on conditions

Hello as the title says have to compare two sheets and get some insides of the data please see the code below. First image is Sheet("scr"), second Sheet("err_data"") last is the result that code below should produce added comments to code.

Products need to match, Posting date should be greater or equal to Confirmation date and Count greater or equal to Available Qty BUom, After this is True then we need to subtract Available Qty BUom from Count and continue with the next product.

Sub Postings()
'! Declare Variables
Application.ScreenUpdating = False
Dim Data, chk, i As Long
Const REPORT = "Report"
'! Store data of scr Table into Array
Data = Sheets("scr").ListObjects(1).Range.Value '! Need to check how many of those went thru sheets("err_clean")
With Sheets("err_clean").ListObjects(1)
    '! Loop data in Array 
NextIteration:    For i = 2 To UBound(Data)
        '! Check for match Sheets("scr").Columns(1) with .ListColumns(1)
        chk = Application.Match(Data(i, 1), .ListColumns(1).Range, 0)
        If Not IsError(chk) Then
                'If .DataBodyRange(chk - 1, 3).Value = 0 Then
                    'If condition is met need to Continue i = i + 1 and jump to Next iteration or Delete row but it get way to slow
                'End If
            '! If match when condition met that's mean scr went thru err_clean
            If Data(i, 2) <= .DataBodyRange(chk - 1, 2).Value And .DataBodyRange(chk - 1, 3).Value - Data(i, 3) >= 0 Then
                'And I have to decrease the quantity of .DataBodyRange(chk - 1, 3).Value
                .DataBodyRange(chk - 1, 3).Value = .DataBodyRange(chk - 1, 3).Value - Data(i, 3)
                '! Check if Sheet exists...If not create sheet
                If Evaluate("ISREF('" & REPORT & "'!A1)") = False Then
                    Sheets.Add(, Sheets(Sheets.Count)).Name = REPORT
                    '! Add header
                    Range("A1").Resize(, 4).Value = .HeaderRowRange.Value
                End If
                
                '! Pass matched data to next available row but I NEED TO APPEND Data(i, 4) to columns number 5 no idea how
                Range("A" & Rows.Count).End(xlUp)(2).Resize(, 4).Value = .ListRows(chk - 1).Range.Value '& Data(i, 4)
                GoTo NextIteration ' Here when we have match and condition i am going to the next item this one went thru
            End If
        End If
    Next i
End With
Application.ScreenUpdating = True

End Sub

Sheet("scr")

Sheet("err_clean")

enter image description here

about 4 years ago · Santiago Trujillo
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda