在B列中编写一个用于搜索字符串值的宏,并获取多行的A列值

时间:2018-12-18 18:23:37

标签: excel vba excel-vba excel-formula

在下表下方,我需要从B列获取所有A列值的列表,字符串为“ not”

有人可以帮我写宏吗?

ColumnA   ColumnB
A           this a A value
B           not available
C           this is C value
D           not found
E           this is E value

output:
B
D

1 个答案:

答案 0 :(得分:1)

如果您想要一个单独的列表,可以这样做:

dim i as integer
dim lastrow as integer
lastrow = 1
do until cells(i,1).value = "" 'loop to the end of the column
    if instr(1,cells(i,2).value,"not")>0 then
        cells(lastrow,3).value = cells(i,1).value 'create list an adjacent column
        lastrow = lastrow + 1 
    end if
    i = i + 1
loop