Nguyen Anh Dung
Board Regular
- Joined
- Feb 28, 2020
- Messages
- 180
- Office Version
- 2016
- Platform
- Windows
nice!!! thanks you so much!!!VBA Code:Sub v() With Range("D2:D" & Cells(Rows.Count, "A").End(3).Row) .Formula = "=IF((A2<>A1)+(COUNTIF(A$2:A2,A2)=4)+(COUNTIF(A$2:A2,A2)=8)+(COUNTIF(A$2:A2,A2)=12)+(A2<>A3),""k"",1)" .SpecialCells(xlCellTypeFormulas, 1).EntireRow.Delete .ClearContents End With End Sub
Hi footoo,nice!!! thanks you so much!!!
You need to explain in more detail.Hi footoo,
if In this case column < 16 rows. only 1 or 2 or 3 or 4 or 5. i want keep it?
thanks you and best regards,
Thanks you reply!!!You need to explain in more detail.
Also, when replying, include any other requirements so as to avoid having to do it in bits and pieces.
Sub v()
Dim rng As Range, a As Range, cel As Range, i%
With Range("D2:D" & Cells(Rows.Count, "A").End(3).Row)
.Formula = "=IF((A2<>A1)+(A2<>A3),1,"""")"
.Value = .Value
Set rng = .SpecialCells(xlCellTypeBlanks)
For Each a In rng.Areas
If a.Count < 4 Then
a = 1
ElseIf a.Count < 11 Then
a(a.Count + 1, 1).ClearContents
[E2].Resize(a.Count + 1) = Evaluate("ROW(1:" & a.Count + 1 & ")")
With [F2].Resize(a.Count + 1)
.Formula = "=RAND()"
.Value = .Value
End With
[E2].Resize(a.Count + 1, 2).Sort Key1:=[F2], Order1:=xlAscending, Header:=xlNo
For i = 1 To 4
a.Item([E2].Item(i, 1)) = 1
Next
[E:F].ClearContents
Else
Union(a(3), a(7), a(11)) = 1
End If
Next
.SpecialCells(xlCellTypeBlanks).EntireRow.Delete
.ClearContents
End With
End Sub
Thanks you so much!!!VBA Code:Sub v() Dim rng As Range, a As Range, cel As Range, i% With Range("D2:D" & Cells(Rows.Count, "A").End(3).Row) .Formula = "=IF((A2<>A1)+(A2<>A3),1,"""")" .Value = .Value Set rng = .SpecialCells(xlCellTypeBlanks) For Each a In rng.Areas If a.Count < 4 Then a = 1 ElseIf a.Count < 11 Then a(a.Count + 1, 1).ClearContents [E2].Resize(a.Count + 1) = Evaluate("ROW(1:" & a.Count + 1 & ")") With [F2].Resize(a.Count + 1) .Formula = "=RAND()" .Value = .Value End With [E2].Resize(a.Count + 1, 2).Sort Key1:=[F2], Order1:=xlAscending, Header:=xlNo For i = 1 To 4 a.Item([E2].Item(i, 1)) = 1 Next [E:F].ClearContents Else Union(a(3), a(7), a(11)) = 1 End If Next .SpecialCells(xlCellTypeBlanks).EntireRow.Delete .ClearContents End With End Sub