【发布时间】:2014-02-22 01:21:46
【问题描述】:
好的,这是我的第一篇文章(当然不是最后一篇,因为我是这个项目的唯一工作人员)。我的 VBA 经验非常少,所以你看到的有点类似于我的“hello world”。
长话短说...我想比较动态范围表中的两行(在打开时从访问数据库中更新)并找到与前四列完全匹配的行(见下面的代码)。
然后比较两个比较行中的最大值的第七列。 (Full、Adequate、Basic是从高到低比较的值)
然后,在满足所有这些标准后,丢弃最低的并保留最高的。 FOR ALL ROWS(也就是 While 循环)。
此代码用于我工作地点的培训数据库,随着员工继续培训,有许多具有不同理解水平的相同条目。此代码应完成所有培训并仅保留最高价值(其能力的最佳代表)并丢弃其他“过时”条目。
这是我毫无价值的代码:
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 列匹配的位置,然后比较最后一列以查看哪个是最高级别并丢弃其他匹配项?
【问题讨论】:
-
感谢您的建议 :) 我编辑了问题,希望它能更好地解释我的问题。
标签: excel comparison row dynamic-data vba