我有一个Excel报告,包含60k行和30列。我想将值H1
与列B:B
中的所有值进行比较,并且当匹配时,我想将值Nx
打印到不同的列BF:BF
或sheet2.A:A
(以较简单的为准),然后转到Hx
等等。Excel宏比较两列Ax,Bx和当不同列中的值为Cx时Dx
请帮我。提前感谢。
我有一个Excel报告,包含60k行和30列。我想将值H1
与列B:B
中的所有值进行比较,并且当匹配时,我想将值Nx
打印到不同的列BF:BF
或sheet2.A:A
(以较简单的为准),然后转到Hx
等等。Excel宏比较两列Ax,Bx和当不同列中的值为Cx时Dx
请帮我。提前感谢。
为什么使用宏?
[BF2] =IF($H$1=B2; N2; "")
[H2] =BF2
此代码将检查列B中的每个单元格与存储在同一工作表的单元格H1中的值。当值匹配,将填写列BF的coresponding电池(行)与列“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
希望这有助于!