If iC > 2 Then
Rows(i).Insert Shift:=xlDown
Range("A" & i & ":BR" & i).Value = Range("A" & i + 1 & ":BR" & i + 1).Value '
For x = 1 To ECol '
ST1 = WorksheetFunction.Small(Range(Cells(i, FCol + 1), Cells(i, FCol + ECol)), 3)
ST2 = WorksheetFunction.Small(Range(Cells(i, FCol + 1), Cells(i, FCol + ECol)), 2)
ST3 = WorksheetFunction.Small(Range(Cells(i, FCol + 1), Cells(i, FCol + ECol)), 1) '
If Cells(i, FCol + x) = ST2 Then
Cells(i, FCol + x) = ST2 + 0.001
ST2 = ST2 + 0.001
End If
Next x '
Cells(i, 5) = ST2 - 0.001
Cells(i + 1, 5) = ST3
For j = 1 To ECol
If Cells(i, j + FCol) > 0 Then
Select Case Cells(i, j + FCol)
Case ST3
Cells(i, j + FCol) = ""
Cells(i + 1, j + FCol) = ST3
Case ST2
Cells(i + 1, j + FCol) = ""
Cells(i, j + FCol) = ST2 - 0.001
Case ST1
Cells(i, j + FCol) = ST2 - 0.001
Cells(i + 1, j + FCol) = ST3
End Select
End If
Next j
ST1 = 0
ST2 = 0
ST3 = 0
End If
ST1 = WorksheetFunction.Small(Range(Cells(i, FCol + 1), Cells(i, FCol + ECol)), 3)
ST2 = WorksheetFunction.Small(Range(Cells(i, FCol + 1), Cells(i, FCol + ECol)), 2)
ST3 = WorksheetFunction.Small(Range(Cells(i, FCol + 1), Cells(i, FCol + ECol)), 1)
VitriST2 = WorksheetFuntion.Match(ST2, Range(Cells(i, FCol + 1), Cells(i, FCol + ECol)), 0)
Cells(i, FCol + VitriST2) = ST2 + 0.001
ST2 = ST2 +0.001
Vận dụng bài trên của PTM0412 mình đã sửa code lại, các bạn góp ý thêm.Lỡ xài Excel Function rồi thì xài tới luôn!
Không dùng For Next nữa mà gán trực tiếp :
Đường vòng này so với đường thẳng thế nào các bạn?PHP:ST1 = WorksheetFunction.Small(Range(Cells(i, FCol + 1), Cells(i, FCol + ECol)), 3) ST2 = WorksheetFunction.Small(Range(Cells(i, FCol + 1), Cells(i, FCol + ECol)), 2) ST3 = WorksheetFunction.Small(Range(Cells(i, FCol + 1), Cells(i, FCol + ECol)), 1) VitriST2 = WorksheetFuntion.Match(ST2, Range(Cells(i, FCol + 1), Cells(i, FCol + ECol)), 0) Cells(i, FCol + VitriST2) = ST2 + 0.001 ST2 = ST2 +0.001