2014-02-22 79 views
-1

好的,問候所有這些是我的第一篇文章(當然,因爲我是這個項目的唯一工作人員,所以這不是我的最後一篇文章)。我有非常小的VBA經驗,所以你看到的有點類似於我的「你好世界」。Excel VBA比較動態單元格區域中的兩行

長話短說...我想比較動態範圍表中的兩行(在打開時從訪問數據庫中更新)並找到與前四列完全匹配的行(請參見下面的內容碼)。

然後比較兩個比較行中最高值的第七列。 (Full,Adquate和Basic是從最高到最低的比較值)

然後,在滿足所有這些標準後,扔掉最低並保持最高。對於所有行(換句話說,一個While循環)。

此代碼適用於我在工作地點的培訓數據庫,因爲員工繼續培訓,因此有許多相同的條目具有不同級別的理解。此代碼應完成所有培訓並保留最高價值(最佳表示能力)並垃圾處理其他「obselete」條目。

這裏是我的一文不值代碼:

Sub RemoveDuplicates() 
Dim Bottom As Integer 
Dim FalseBottom As Integer 
'remove lower leveled duplicate entries 
Bottom = CInt(Cells(Rows.Count, "A").End(xlUp).Row) 'initializes the bottom of the list (total number of entries) 
Do Until Bottom = 0 
FalseBottom = 1 
If Not IsEmpty(Cells(Bottom, "A")) Then 
    Do Until FalseBottom = Bottom 
    If ((Cells(FalseBottom, "A").Text = Cells(Bottom, "A").Text) And (Cells (FalseBottom, "B").Text = Cells(Bottom, "B").Text) And (Cells(FalseBottom, "C").Text = Cells(Bottom, "C").Text) And (Cells(FalseBottom, "D").Text = Cells(Bottom, "D").Text)) Then 
    '(Cells(FalseBottom, "G").Text > Cells(Bottom, "G").Text) 
    If (Cells(Bottom, "G").Text = "Full") Then 
    Rows(FalseBottom).Delete Shift:=xlUp 
    FalseBottom = FalseBottom - 1 
    End If 
    If ((Cells(Bottom, "G").Text = "Adequate") And (Cells(FalseBottom, "G").Text = "Basic")) Then 
    Rows(FalseBottom).Delete Shift:=xlUp 
    FalseBottom = FalseBottom - 1 
    End If 
    If (Cells(FalseBottom, "G").Text = "Full") Then 
    Rows(Bottom).Delete Shift:=xlUp 
    End If 
    If ((Cells(FalseBottom, "G").Text = "Adequate") And (Cells(Bottom, "G").Text = "Basic")) Then 
    Rows(Bottom).Delete Shift:=xlUp 
    End If 
    End If 
    FalseBottom = FalseBottom + 1 
    Loop 
    End If 
Bottom = Bottom - 1 
Loop 
End Sub 

更好地解釋。此外,在我的Excel工作表中我有

A |B |C  |D  |E   |F   |G 
--------------------------------------------------------------- 
First|Last |Category|Task |Performance|Requirement|Understanding 
--------------------------------------------------------------- 
Joe |Smoe |Cleaning|Toilets|10   |10   |Basic 
Joe |Smoe |Cleaning|Toilets|10   |10   |Adequate 
Joe |Smoe |Cleaning|Toilets|10   |10   |Full 
Joe |Smoe |Cleaning|Showers|10   |10   |Basic 
Jane |Plane|Cleaning|Toilets|10   |10   |Basic 
... 
... 

基本上是有辦法找到(在所有行)地方的前4列匹配,然後比較最後一列以查看哪一個是最高級別並丟棄其他匹配?

+1

歡迎來到SO! [見此](http://stackoverflow.com/help/on-topic),特別是**號碼**。你已經包含了太多的代碼,並且包含了很多難以幫助你的廣泛陳述。請嘗試調試您的代碼([見此](http://www.cpearson.com/excel/DebuggingVBA.aspx)),並修改您遇到的具體問題的問題。 – ARich

+0

謝謝你的建議:)我編輯了這個問題,希望能更好地解釋我的問題。 – user3339460

回答

0

固定問題!

改變。文本到.value的

拆分分開的if語句

分配的值thier的可讀性

自己的變量和工作就像一個魅力...不知道爲什麼,但我會採取的。

相關問題