2014-02-22 3 views
-1

Ok, 인사말은 내 첫 번째 게시물입니다 (이 프로젝트에서 유일한 사람이므로 내 마지막은 아닙니다). 나는 아주 아주 작은 VBA 경험을 가지고있어서 당신이 보는 것은 내 "안녕하세요 세상"과 비슷합니다.Excel VBA에서 동적 셀 범위의 두 행을 비교합니다.

짧은 이야기를 나누려면 ... 동적 원거리 시트 (열 때 액세스 데이터베이스에서 업데이트 됨)의 두 행을 비교하고 처음 네 열에 정확히 일치하는 행을 찾습니다 (아래 참조). 암호).

그런 다음 비교 된 두 행 중에서 가장 높은 값에 대해 일곱 번째 열을 비교하십시오. (Full, Adequate 및 Basic은 가장 높은 값에서 가장 낮은 값으로 비교할 값입니다.)

그런 다음이 모든 기준을 충족하면 최저값을 버리고 최고 값을 유지하십시오. ALL ROWS (즉, 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 

더 나은 기본적으로 배치합니다 (모든 행을 전역) 찾을 수있는 방법이 더 내 엑셀 시트에 내가

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

안녕하세요! [참조하십시오] (http://stackoverflow.com/help/on-topic), 특히 ** 번호 1 **. 너무 많은 코드를 포함 시켰으며, 당신에게 도움이되는 광범위한 진술을 포함 시켰습니다. 코드를 디버깅 해보십시오 ([[참고]) (http://www.cpearson.com/excel/DebuggingVBA.aspx)), 완료되면 특정 문제로 질문을 수정하십시오. – ARich

+0

조언 해 주셔서 감사합니다. 나는 질문을 편집했으며 잘하면 내 문제를 더 잘 설명합니다. – user3339460

답변

0

고정 문제!

따로 따로 만약 문

가독성

에 대한 자신의 변수를 아쉬워하는 값을 할당

분할 .Value하기는 .text을 변경하고 매력 ... 단서 왜하지만처럼 일 가져가.

관련 문제