각 열에 키워드가 포함된다고 가정하면 설정 가능한 범위의 행으로 넘어 가서 r 해당 행에 두 번 이상 나타나는 모든 키워드를 제거하십시오.
Sub DeleteDuplicateKeywords()
Dim rng As Range
Dim r As Long 'row iterator
Dim rowRng As Range ' a separate range for each ROW in rng.
Dim c As Long 'column iterator
Dim sKeyword As String
Dim bReview As Boolean
bReview = MsgBox("Do you want to preview which cells will be deleted?", vbYesNo)
Set rng = Range("B13:E18") '<-- change this as necessary for your requirements.
For r = 1 To rng.Rows.Count 'iterate over each ROW in the range
Set rowRng = rng.Rows(r)
For c = rowRng.Columns.Count To 1 Step -1 'iterate backwards over the columns, ignoring the first column.
sKeyword = rowRng.Cells(c).Value 'assign the cell value to a variable
'Check to see if this keyword exists more than once in this row
If Application.WorksheetFunction.CountIf(rowRng, sKeyword) > 1 Then
'if it does, then delete it.
If bReview Then
rowRng.Cells(c).Interior.ColorIndex = 39
Else:
rowRng.Cells(c).Delete Shift:=xlToLeft
End If
End If
Next
Next
End Sub
당신은 "키워드의 다른 번호를 가지고 수있는 다양한 아이템"다음 "키워드가 각 항목의 중복 항목이"라고, 그래서 어떤 포함하는 확실하지 않다. 나는 또한 "A"가 여러 개의 셀을 나타내는 지 아니면 하나의 셀이 여러 개의 ... somethings ...가 공백으로 구분되어 있는지를 알 수 없다. 또한 일반적으로 Excel 열 머리글로 행의 레이블을 지정하는 데 도움이되지 않습니다. 또한 어떤 Excel 버전입니까? –
예를 들어, 각 키워드가 별도의 셀에 있습니까? A1 = "A", B1 = "123", "C1 ="234 "',"D1 = "456"'.... 또는 A1 = "A"', B1 = "123 234 456 123 234" – NickSlash
A1 = "A", B1 = "123", C1 = "234", D1 = "456"입니다. – elephant