2014-07-03 42 views
1

我有號碼的清單,我想找到所有包含的數字如何找到含有數字的子集,所有的數字

例如子集的數字:

 
column A 
34523423 
43243444 
3443243 
342323 
342345 
3445454 
5345365 

鑑於上面的列表,我想查找包含子集44的所有數字。如果有一個匹配的數量應該被複制到B列
所以,在這個例子中,B列應該包含

 
43243444 
3443243 
3445454 

這是我到目前爲止有:

Sub find_numb() 

Dim i as integer 
Dim j as integer 

i = 1 
j = 1 

'Cells(6, 12) will contain the number that I am looking up 

look_up = Cells(6, 12) 

Do While i < 605 

If InStr(look_up, Cells(i, 1)) Then 
    Cells(j,2) = Cells(i, 1) 
    j = j + 1 
End If 
i = i + 1 
Loop 


End Sub 

這導致例如,如果我的輸入是43,在我的列表中是43和4443,那麼輸出只有43.

+2

您到目前爲止嘗試過什麼?你將它標記爲[tag:vba],但我沒有看到VBA代碼。 – L42

回答

1

您有點交換了InStr參數,所以試試這個:

Do While i < 605 
    If InStr(Cells(i, 1), look_up) <> 0 Then 
     Cells(j,2) = Cells(i, 1) 
     j = j + 1 
    End If 
    i = i + 1 
Loop 
相關問題