Excelmacros比较两列Ax,Bx以及何时在不同列Dx中打印值Cx

我有一个60k行和30 +列的Excel报告。 我想比较值H1和列B:B所有值,当匹配时,我想将值Nx打印到不同的列BF:BFsheet2.A:A (以较简单的为准),然后移到Hx等。

请帮我。提前感谢。

为什么使用macros?

 [BF2] =IF($H$1=B2; N2; "") [H2] =BF2 

此代码将检查列B中的每个单元格存储在同一工作表的单元格H1中的值。 当这些值匹配时,它将填充栏BF中的相应的单元格(按行)与列“N”值:只需填写您的工作表名称,并最终设置一个较小的行数(到10000)

 Sub CompareValues () Dim Wks as Worksheet: Set Wks = Sheets("YourWorkSheetName") ' in this worksheet the code will do the lookup and copy values Dim Wks2 as Worksheet: Set Wks2 = Sheets("YourOtherWorkSheetName") ' in this sheet (2) the code will optionally copy the values CompareValue = Wks.Range("H1").value Dim I as integer for i = 1 to 10000 ' you can set a smaller value thow If Wks.Range("B"&i) = CompareValue then Wks.Range("BF"&i).Value = Wks.Range("N"&i) ' to fill the value into another sheet simply replace the Wks with Wks2 ' Wks2.Range("BF"&i) = = Wks.Range("N"&i) end if next i End Sub 

希望这可以帮助!