Copiar datos desde una fichero Excel a otro con condición
Tengo un problema con un VBA que estoy intentado crear, necesito copiar datos hacia un fichero excel que tengo abierto desde otro, pero solo aquellos datos cuya columna sea igual a "P".
Me explico, desde un formulario Excel capturo datos en una archivo "Origen.xslm", relleno toda la información y lo marco con una "P" en la columna "J" de forma que esos datos que tienen la "P" los quiero pasar al libro "Destino.xslm" que es el que contiene el VBA y que tengo abierto.
La idea es pasar los datos y una vez pasados borrar la "P" para que cuando se sigan capturando datos en Origen.xslm, solo se pasen los que aún no he pasado, el resto no se copian.
Tengo hecho lo siguiente:
Sub ImportarDatos()
'creamos las variables
Dim UltFila As Long
Dim ultfila2 As Long
Dim FECHA As Date
Dim HORA As Date
Dim GESTOR As String
Dim AGENCIA As String
Dim NOTAS As String
Dim TINFORME As String
Dim NPCO As Double
Dim USUARIO As String
Dim COPIADO As String
Dim cont As Long
Dim wbLibroOrigen As Workbook
Dim wsHojaOrigen As Worksheet
Dim wbLibroDestino As Workbook
Dim wsHojaDestino As Worksheet
Dim ruta As String
Dim SourceFile, DestinationFile
Dim Celda As Range
Dim ultfila3 As Long
ruta = "I:\Origen.xlsm" ' Define Origen
'Datos Origen
Set wbLibroOrigen = Workbooks.Open(ruta)
Set wsHojaOrigen = wbLibroOrigen.Worksheets("DATOS")
'Datos Destino
Set wbLibroDestino = Workbooks(Thisworkbook.Name)
Set wsHojaDestino = wbLibroDestino.Worksheets("DATOS")
UltFila = wsHojaOrigen.Range("B" & Rows.Count).End(xlUp).Row
For cont = 2 To UltFila
FECHA = Sheets("DATOS").Cells(cont, 2)
HORA = Sheets("DATOS").Cells(cont, 3)
GESTOR = Sheets("DATOS").Cells(cont, 4)
AGENCIA = Sheets("DATOS").Cells(cont, 5)
NOTAS = Sheets("DATOS").Cells(cont, 6)
TINFORME = Sheets("DATOS").Cells(cont, 7)
NPCO = Sheets("DATOS").Cells(cont, 8)
USUAGENCIA = Sheets("DATOS").Cells(cont, 9)
COPIADO = Sheets("DATOS").Cells(cont, 10)
If COPIADO = "P" Then
ultfila2 = wsHojaDestino.Range("B" & Rows.Count).End(xlUp).Row
Sheets("DATOS").Cells(ultfila2 + 1, 2) = FECHA
Sheets("DATOS").Cells(ultfila2 + 1, 3) = HORA
Sheets("DATOS").Cells(ultfila2 + 1, 4) = GESTOR
Sheets("DATOS").Cells(ultfila2 + 1, 5) = AGENCIA
Sheets("DATOS").Cells(ultfila2 + 1, 6) = NOTAS
Sheets("DATOS").Cells(ultfila2 + 1, 7) = TINFORME
Sheets("DATOS").Cells(ultfila2 + 1, 8) = NPCO
Sheets("DATOS").Cells(ultfila2 + 1, 9) = USUAGENCIA
End If
Next cont
' borramos la P de la columna J
ultfila3 = Range("J" & Rows.Count).End(xlUp).Row
For Each Celda In Range("J2:J" & ultfila3)
If (Celda.Value = "P") Then Celda.ClearContents
Next Celda
End Sub
He hecho esto pero no me funciona, no me pega los datos, he buscado información pero solo encuentra tutoriales para copiar en el mismo excel o de uno a otro pero toda la información
