현재 통합 문서에서 중복을 식별하는 매크로를 실행하고 있지만 색인에서 첫 번째 집합을 식별하고 첫 번째 집합에 태그를 지정하지 않아 if 문을 설정하게되었습니다 to this by는 첫 번째 인스턴스에도 중복을 추가합니다. 그러나이 작업을 수행하는 데 오랜 시간이 걸리고 가능한 경우이를 향상시키고 자합니다. 어떤 제안이라도 대단히 감사 할 것입니다. 저는 VBA에 처음 왔지만 새로운 문제가 생겨서 조금 배우고 있습니다!VBA - IF 루프 개선
'Declaring the lastRow variable as Long to store the last row value in the Column1
Dim lastRow As Long
'matchFoundIndex is to store the match index values of the given value
Dim matchFoundIndex As Long
'iCntr is to loop through all the records in the column 1 using For loop
Dim iCntr As Long
Dim first_dup As Long
Dim tagging As Long
Dim item_code As String
'Finding the last row in the Column 1
lastRow = Range("B1000000").End(xlUp).Row
'
'looping through the column1
For iCntr = 2 To lastRow
'checking if the cell is having any item, skipping if it is blank.
If Cells(iCntr, 1) <> "" Then
'getting match index number for the value of the cell
matchFoundIndex = WorksheetFunction.Match(Cells(iCntr, 1), Range("A1:A" & lastRow), 0)
'if the match index is not equals to current row number, then it is a duplicate value
If iCntr <> matchFoundIndex Then
'Printing the label in the column B
Cells(iCntr, 4) = "Duplicate"
End If
End If
Next
For first_dup = 2 To lastRow
If Cells(first_dup, 5) = "Duplicate" Then
item_code = Cells(first_dup, 1)
For tagging = 2 To lastRow
If Cells(tagging, 1) = item_code Then
Cells(tagging, 5) = "Duplicate"
End If
Next
End If
Next
Example data:
item code
1
2
3
4
1 duplicate
2 duplicate
3 duplicate
4 duplicate
1 duplicate
2 duplicate
3 duplicate
4 duplicate
개별 범위/셀을 사용하는 대신 Range.Value 배열을 반복하면 도움이됩니다. '= IF (MATCH ($ A2, $ A : $ A, 0) <> ROW ($ A2), "Duplicate", "") 같은 공식을 사용하여 동일한 결과를 얻을 수도 있습니다. –