2014-07-10 39 views
0

讓我們開始在我的工作簿中的某些值怎麼看起來像一個例子:我想打一個腳本,複製B列中的值發現重複,結合下一個單元格值的一部分重複

 
     A  B   C 
1  14-001 2014G001 
2  14-002 2014G002 
3  14-001 2014I002 

C,並且如果列A中的單元格值相同,則組合這些值的最後4個字符。運行該腳本後它應該看起來像:

 
     A  B   C 
1  14-001 2014G001 G001/I001 
2  14-002 2014G002 G002 
3  14-001 2014I001 

我從來沒有找到重複,我無法在網上找到類似的問題。有人可以幫我嗎?

謝謝!

回答

0

我實際上是自己做的:)現在我必須找出如何改變它,當有3個相同的..有人嗎?

Sub test() 

Dim toAdd As Boolean, uniqueNumbers As Integer, i As Integer, j As Integer 

Dim A$, B$ 

Cells(1, 4).Value = Cells(1, 1).Value 
Cells(1, 5).Value = Cells(1, 2).Value 

uniqueNumbers = 1 
toAdd = True 

For i = 2 To 30 
For j = 1 To uniqueNumbers 
If Cells(i, 1).Value = Cells(j, 4).Value Then 
    toAdd = False 

    A = Right(Cells(i, 2), 4) 
    B = Right(Cells(j, 2), 4) 
    Cells(j, 5).Value = A & "/" & B 


End If 
Next j 

If toAdd = True Then 
Cells(uniqueNumbers + 1, 4).Value = Cells(i, 1).Value 
Cells(uniqueNumbers + 1, 5).Value = Cells(i, 2).Value 
uniqueNumbers = uniqueNumbers + 1 
End If 

toAdd = True 

Next i 

End Sub