Actualmente tengo dos hojas: Sheet1 y Sheet2.
La Hoja 1 consta de información del sistema para elementos (Origen) y la Hoja 2 es la Hoja de destino (Objetivo).
Necesito poder filtrar la Columna A (Fuente) por el valor que se escribe en la Celda A3 en la Hoja de destino y luego pegar los datos en la primera fila disponible en la hoja de Destino. Parece estar fallando en la última línea de código, no estoy muy seguro de por qué. Agradezco cualquier ayuda.
El error que recibo es: Error en tiempo de ejecución '1004': Error en el método 'Rango' del objeto'_Hoja de trabajo'
Sub CopyRowAndBelowToTarget() Dim wb As Workbook Dim src As Worksheet Dim tgt As Worksheet Dim match As Range Set wb = ThisWorkbook Set src = wb.Sheets("Sheet1") Set tgt = wb.Sheets("Sheet2") Dim lastCopyRow As Long Dim lastPasteRow As Long Dim lastCol As Long Dim matchRow As Long Dim findMe As String Sheets("sheet2").Activate ' specify what we're searching for findMe = Range("B1").Value 'Filter column for value src.Range("A1").AutoFilter Field:=1, Criteria1:=findMe ' find our search string in column A (1) Set match = src.Columns(1).Find(What:=findMe, After:=src.Cells(1, 1), _ LookIn:=xlValues, LookAt:=xlWhole, SearchOrder:=xlByRows, _ SearchDirection:=xlNext, MatchCase:=False, SearchFormat:=False) ' figure out what row our search string is on matchRow = match.Row ' get the last row and column with data so we know how much to copy lastCopyRow = src.Range("A" & src.Rows.Count).End(xlUp).Row lastCol = src.Cells(1, src.Columns.Count).End(xlToLeft).Column ' find out where on our target sheet we should paste the results lastPasteRow = tgt.Range("A" & src.Rows.Count).End(xlUp).Row ' use copy/paste syntax that doesn't use the clipboard ' and doesn't select or activate src.Range(Cells(matchRow, 1), src.Cells(lastCopyRow, lastCol)).Copy _ tgt.Range("A" & lastPasteRow)