Comparar entre hoja 1 y hoja 2 los registro que no se encuentran y los corta y pega en hoja3

con este código realiza la comparación copia y pega, pero necesito que corte la diferencia y la pegue en la otra hoja:

Sub BuscayCopia()
Application.ScreenUpdating = False
Dim fila, filat, uc1, uc2 As Integer
Dim d1, d2, d3, d4, d5, d6 As String
Dim b, con1, con2 As String
fila = 2
fila1 = 2
filat = 2
Sheets("depurados").Select
Range("a2:XFD1048576").Clear
uc1 = Sheets("hoy").Cells(1, Columns.Count).End(xlToLeft).Column
uc1 = uc1 + 1
uc2 = Sheets("d-1").Cells(1, Columns.Count).End(xlToLeft).Column
uc2 = uc2 + 1
While Sheets("hoy").Cells(fila, 1) <> Empty
d1 = Sheets("hoy").Cells(fila, 4).Text
d2 = Sheets("hoy").Cells(fila, 5).Text
d3 = Sheets("hoy").Cells(fila, 7).Text
con1 = d1 & d2 & d3
Sheets("hoy").Cells(fila, uc1) = con1
fila = fila + 1
Wend
fila = 2
While Sheets("d-1").Cells(fila, 1) <> Empty
d4 = Sheets("d-1").Cells(fila, 4).Text
d5 = Sheets("d-1").Cells(fila, 5).Text
d6 = Sheets("d-1").Cells(fila, 7).Text
con2 = d4 & d5 & d6
Sheets("d-1").Cells(fila, uc2) = con2
fila = fila + 1
Wend
fila = 2
While Sheets("hoy").Cells(fila, uc1) <> Empty
dato = Sheets("d-1").Cells(fila, uc2)
Set b = Sheets("hoy").Columns(uc1).Find(dato, LookIn:=xlValues, Lookat:=xlWhole)
If b Is Nothing Then
Sheets("d-1").Select
Rows(fila).Select
Selection.Copy
Sheets("depurados").Select
Cells(filat, 1).Select
Selection.PasteSpecial Paste:=xlPasteFormulas, Operation:=xlNone, _
SkipBlanks:=False, Transpose:=False
Application.CutCopyMode = False
filat = filat + 1
End If
fila = fila + 1
Wend
Sheets("depurados").Columns(5).Select
Selection.NumberFormat = "#,##0"
Sheets("hoy").Columns(uc1).Clear
Sheets("d-1").Columns(uc2).Clear
Sheets("depurados").Columns(uc2).Clear
Set b = Nothing
Application.ScreenUpdating = False
End Sub

2 respuestas

Respuesta
1

Puedes probar lo siguiente y decirme si te funciona

Reemplaza esta parte :

Selection. Copy
Sheets("depurados").Select
Cells(filat, 1).Select
Selection.PasteSpecial Paste:=xlPasteFormulas, Operation:=xlNone, _
SkipBlanks:=False, Transpose:=False

Por esta:

Selection.Cut
Sheets("depurados").Select
Cells(filat, 1).Select
ActiveSheet.Paste

O prueba esta otra opción, agrega al final de este código

Sheets("d-1").Select
Rows(fila).Select
Selection.Copy
Sheets("depurados").Select
Cells(filat, 1).Select
Selection.PasteSpecial Paste:=xlPasteFormulas, Operation:=xlNone, _
SkipBlanks:=False, Transpose:=False
Application.CutCopyMode = False

Lo siguiente:

Sheets("d-1").Select
Rows(fila).ClearContents

Te quedaría así

Sheets("d-1").Select
Rows(fila).Select
Selection.Copy
Sheets("depurados").Select
Cells(filat, 1).Select
Selection.PasteSpecial Paste:=xlPasteFormulas, Operation:=xlNone, _
SkipBlanks:=False, Transpose:=False
Application.CutCopyMode = False
Sheets("d-1").Select
Rows(fila). ClearContents

Prueba y me comentas, si no funciona revisamos otras opciones

Saludos. Dam
Si es lo que necesitas.

Respuesta
1

Como estás, en vez de utilizar Selection. Copy utiliza Selection. Cut

Con eso cortas en vez de copiar, cierra la pregunta no te olvides

Añade tu respuesta

Haz clic para o

Más respuestas relacionadas