Copy entire row if the column contains any value of another column in VBA -
i'm new in vba. have 3 sheets: 'sunday', 'coords' , 'filtered'. want check if 'a' column of sheet 'sunday' equal of values in column 'j' of 'coords' sheet. if true - copy row in 'filtered' sheet.
so far have tried following code:
sub copyrow() dim lastrow long dim sheetname1 string dim sheetname2 string dim sheetname3 string sheetname1 = "sunday" 'insert sheet name here sheetname2 = "coords" sheetname3 = "filtered" lastrow = sheets(sheetname1).range("a" & rows.count).end(xlup).row lrow = 2 lastrow 'loop through rows if sheets(sheetname1).cells(lrow, "a") = sheets(sheetname2).cells(lrow, "j") c.entirerow.copy worksheets(sheetname3).range("a" & rows.count).end(xlup).offset(1) end if next lrow end sub
any appreciated
if want check existence of value @ any row of column j
, try this:
if application.countif(sheets(sheetname2).columns("j"), sheets(sheetname1).cells(lrow, "a").value2) > 0 sheets(sheetname3).range("a" & rows.count).end(xlup).offset(1).entirerow.value = sheets(sheetname1).rows(lrow).value2 end if
Comments
Post a Comment