我想实现这个功能该如何实现
我想将A1,A2,A3的值分别依次与B1,B2,B3的值进行比较,即A1与B1,B2,B3比较,若相等则将A1的值写入C1;A2与B1,B2,B3比较,若相等则将A2的值写入C2;A3与B1,B2,B3比较,若相等则将A3的值写入C3;请问该如何写代码实现,谢谢
[解决办法]
不太好=IF(ISERROR(VLOOKUP(A1,$B$1:$B$6,1,FALSE)),0,A1)可以吧
[解决办法]
[C1] = iif(worksheetfunction.CountIf([b1:b3],[a1]),[a1],"")
[解决办法]
看来楼主偏爱硬代码了,那么写个双重循环就行了
大概这样,随便写一个,没有测试,楼主自己验证吧
for i=1 to 3 for j=1 to 3 if cells(i,1) = cells(j,2) then cells(i,3) = cells(i,1) end if nextnext
[解决办法]
Sub test()On Error GoTo next_line Dim rng1 As Range, rng2 As Range, rngcell As Range Set rng1 = ActiveSheet.Range("B1:B3") Set rng2 = ActiveSheet.Range("A1:A3") For Each rngcell In rng2 If Not IsError(WorksheetFunction.VLookup(rngcell, rng1, 1, False)) Then rngcell.Offset(0, 2) = rngcellnext_line: NextEnd Sub