View Single Post
  #1   Report Post  
Posted to microsoft.public.excel.programming
L. Howard L. Howard is offline
external usenet poster
 
Posts: 852
Default If value occurs more than once then delete all of them

If a value in varData occurs more than once, then delete all same values in varData and list remaining values in column F.

Values as either Integers or text or both, if possible.

This code does not like the CountIf.

Thanks.
Howard


Sub LoneValueStay()
Dim varData As Variant
Dim i As Long

varData = Sheets("Sheet1").Range("A2:D15") '// Read in the data.

For i = LBound(varData) To UBound(varData)
If Application.WorksheetFunction.CountIf(varData(i, varData)) 1 Then
varData(i) = ""
'varData(i).Delete
End If
Next i

'// Write result to sheet.
'Sheets("Sheet1").Range("F1").Resize(UBound(varDat a) - LBound(varData) + 1, 1) _
= varData
End Sub