Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

161
Vistas
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 la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda