如何在sepearte ws中调和列,并在第三个ws中返回缺失的行?

晚间,

我试图比较ws“Consolidated”的列“A”(从第二行开始)到ws“OTL”的列“D”(从第十七行开始)的数据。 对于每一个不匹配,应该在第三个工作表中创build一个新行“和解”(理想情况下,整个行将被复制,但我会很高兴与数字)

这是我必须要约会的:

Sub Differentiation() Set RECsheet = ThisWorkbook.Sheets("Reconciliation") Set OTLsheet = ThisWorkbook.Sheets("OTL") Set CONsheet = ThisWorkbook.Sheets("Consolidation") lrREC = RECsheet.Cells(Sheets("RECsheet").Rows.Count, "A").End(xlUp).Row lrOTL = ORLsheet.Cells(Sheets("OTLsheet").Rows.Count, "D").End(xlUp).Row lrCON = CONsheet.Cells(Sheets("CONsheet").Rows.Count, "A").End(xlUp).Row For i = 2 To lrCON foundTrue = False For j = 17 To lrOTL If Sheets("CONSheet").Cells(i, 1).Value = Sheets("OTLsheet").Cells(j, 4).Value Then foundTrue = True Exit For End If Next j If Not foundTrue Then Sheets("CONSheet").Rows(i).Copy Destination:= _ Sheets("Consolidation").Rows(lrREC+ 1) lrREC = lrREC + 1 End If Next i 'stop screen from updating to speed things up Application.ScreenUpdating = True End Sub 

我知道这可能看起来像一只狗的早餐,但我确实很努力(在这14小时!!!哈哈)

会爱你的帮助!

我把它分成两部分。 首先,find不匹配:像iferror(vlookup(ThingToLookup,TableInOtherWS,1,0),"MISMATCH") 。 把它全部复制下来。 这会给你一个不匹配的列表。 然后做一些像(我不testing这个,但你应该明白我的观点)

 'start in the WS with the MISMATCH column, with the first range of that column selected dim arr(10000,2) 'assuming you want to copy over 3 fields... increase for more fields... and assuming 10000 rows i=0 while activecell.value <>"" if activecell.value ="MISMATCH" then arr(i,0)=activecell.offset(0,-4).value 'change -4 to whatever u wanna copy arr(i,1)=activecell.offset(0,-3).value arr(i,2)=activecell.offset(0,-2).value end if i=i+1 activecell.offset(1,0).activate wend 'now dump out results in a new book worksheet.add for i_ctr = 0 to i activecell.offset(i_ctr ,0).value= arr(i_ctr,0) activecell.offset(i_ctr ,1).value= arr(i_ctr,1) activecell.offset(i_ctr ,2).value= arr(i_ctr,2) next 

通过逐行推F8来缓慢运行,看看它是如何进行的。 祝你好运!