2013-10-03 46 views

回答

2

为什么使用宏?

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

此代码将检查列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 

希望这有助于!