2013-10-03 96 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 

希望這有助於!