Macro que compare valores de sos libros

Macro

Tengo un libro llamado "libro1" de ahí quiero tener el botón para correr la macro quiero que al correrla me abra la ventana para yo seleccionar que archivo abrir de excel que este varia el nombre al momento de abrirlo me filtre por dos criterios primero la columna E EL CRITERIO WL3 Y DESPUÉS LA COLUMNA V el criterio est config y system ya filtrado quiero que me compare la columna DE del libro 1 con la columna G del libro que abrimos si un valor del libro que abrimos no esta en en libro copie la fila y la traiga al libro 1

1 respuesta

Respuesta
4

Te anexo una macro

Sub comparar()
'Por.Dante Amor
    Application.ScreenUpdating = False
    Set l1 = ThisWorkbook
    Set h1 = l1.ActiveSheet
    'abrir archivo
    arch = Application.GetOpenFilename("Excel (*.xls*), *.txt*")
    If arch = False Then Exit Sub
    Set l2 = Workbooks.Open(arch)
    Set h2 = l2.Sheets(1)
    For i = 1 To h2.Range("G" & Rows.Count).End(xlUp).Row
        If h2.Cells(i, "E") = "WL3" And _
           (UCase(h2.Cells(i, "V")) = "EST" Or _
            UCase(h2.Cells(i, "V")) = "SYSTEM" Or _
            UCase(h2.Cells(i, "V")) = "CONFIG") Then
            For j = 1 To h1.Range("D" & Rows.Count).End(xlUp).Row
                If h1.Cells(j, "D") = h2.Cells(i, "G") Then
                    existe = True
                    Exit For
                End If
            Next
            If existe = False Then
                h2.Rows(i).Copy h1.Range("A" & h1.UsedRange.Rows(h1.UsedRange.Rows.Count).Row + 1)
            End If
            existe = False
        End If
    Next
    l2.Close
    MsgBox "Libro actualizado", vbInformation
End Sub

Prueba y me comentas

Que tal buen día

Excelente la macro solo que en este caso me gustaría que no copiara toda la fila si no datos en especifico de esa fila la columna "D" "E" "F" "G" "I"

¿Y en qué columna quieres que se pegue cada una de ellas?

A partir de la columna "A"  EN ESE ORDEN 

Te anexo la macro con la corrección

Sub comparar()
'Por.Dante Amor
    Application.ScreenUpdating = False
    Set l1 = ThisWorkbook
    Set h1 = l1.ActiveSheet
    'abrir archivo
    arch = Application.GetOpenFilename("Excel (*.xls*), *.txt*")
    If arch = False Then Exit Sub
    Set l2 = Workbooks.Open(arch)
    Set h2 = l2.Sheets(1)
    For i = 1 To h2.Range("G" & Rows.Count).End(xlUp).Row
        If h2.Cells(i, "E") = "WL3" And _
           (UCase(h2.Cells(i, "V")) = "EST" Or _
            UCase(h2.Cells(i, "V")) = "SYSTEM" Or _
            UCase(h2.Cells(i, "V")) = "CONFIG") Then
            For j = 1 To h1.Range("D" & Rows.Count).End(xlUp).Row
                If h1.Cells(j, "D") = h2.Cells(i, "G") Then
                    existe = True
                    Exit For
                End If
            Next
            If existe = False Then
                h2.Range("D" & i & ",E" & i & ",F" & i & ",G" & i & ",I" & i).Copy _
                    h1.Range("A" & h1.UsedRange.Rows(h1.UsedRange.Rows.Count).Row + 1)
            End If
            existe = False
        End If
    Next
    l2.Close
    MsgBox "Libro actualizado", vbInformation
End Sub

Recuerda valorar la respuesta.

¡Gracias! 

¡Gracias! 

Podrías valorar la respuesta.

Al final de mi respuesta dice: “Es una buena respuesta” y puedes seleccionar una de 3 opciones:

- Excelente

- Si

- No

Añade tu respuesta

Haz clic para o

Más respuestas relacionadas