2014-09-05 86 views
0

所以我正在研究一個基本的宏,現在我需要比較兩列的重複項。OpenOffice比較兩個單元格字符串

這裏是我迄今打算:

for i = 0 To 5 
    Cell1 = Sheet.getCellByPosition(0,i) 

    for j = 0 to 5 
    Cell2 = Sheet.getCellByPosition(1,j) 

    rem COMPARISON WOULD HAPPEN HERE 

    Next j 
Next i 

我願做線沿線的東西:如果Cell1.String == Cell2.String然後...

這是我的首先嚐試編寫一個宏,所以我非常感謝任何幫助和/或指導。

謝謝!

同樣在一個側面說明,如果有人知道好tutorials.documentation比維基這個其他的,我將非常感謝您的鏈接

回答

0

你應該第一列的所有值存儲到一個數組,然後比較第二列的每個值都與數組中的所有條目一起使用簡單的遞歸。

可工作的代碼是

Dim firstcolumn(5) As String 

For i = 0 to 5 
    firstcolumn(i) = Sheet.getCellByPosition(0,i) 
Next i 

For j = 0 to 5 
    Cell2 = Sheet.getCellByPosition(1,j) 
    for i = 0 to 5 
    if Cell2 = firstcolumn(i) then 
     MsgBox("The value of the cell " + i + " in the first column is the same with the value of the cell " + j + " of the second column") 
    Next i 
Next j 

尋找代碼樣本的最佳位置是OpenOffice的論壇https://forum.openoffice.org/en/forum/

我希望上面會幫你的。