Option Explicit
Sub AddRow20()
Dim jJ As Long, eRw As Long, SoNgau As Double, MColor As Byte, DG As Double
Dim B1 As Range, C1 As Range, GPE As Boolean
eRw = 2 * [B65500].End(xlUp).Row '<=| Tang Doi Só Dòng Càn Xu Lí'
With [A1].Interior
If .ColorIndex < 34 Or .ColorIndex > 42 Then
MColor = 35
Else
MColor = .ColorIndex + 1
End If
.ColorIndex = MColor
End With
For jJ = 3 To eRw
If Cells(jJ, "B").Value > Cells(jJ - 1, "B").Value + 20 Then
GPE = True
Cells(jJ, "B").EntireRow.Insert
DG = Cells(jJ + 1, "B") - Cells(jJ - 1, "B") - 15
Randomize: SoNgau = 7 + 9 * Rnd()
Cells(jJ, "B").Value = SoNgau + Cells(jJ - 1, "B").Value
Set B1 = Cells(jJ - 1, "B"): Set C1 = B1.Offset(, 1)
Cells(jJ, "c").Value = C1 + ((C1.Offset(2) - C1) * (B1.Offset(1) - B1)) / (B1.Offset(2) - B1)
Cells(jJ, "B").Interior.ColorIndex = MColor
jJ = jJ + 1
Else
End If
Cells(jJ, "A").Value = 1 + Cells(jJ - 1, "A")
Next jJ
If GPE Then
GPE = False: AddRow20
Else
Cells([B65500].End(xlUp).Row + 1, "A").Resize(eRw).ClearContents
Exit Sub
End If
Set C1 = [d1]: jJ = 0
GPE = False: eRw = 0
SoNgau = CInt(Right([A1], 1))
For Each B1 In Range([B2], [B65500].End(xlUp))
eRw = 1 + eRw
If B1.Interior.ColorIndex > 9 Then jJ = jJ + 1
If GPE = True Then B1.Offset(, -1).Value = eRw
If B1.Value = "" Then
C1.Value = "Add " & jJ & " rows": GPE = True
Set C1 = B1.Offset(, 2): jJ = 0
SoNgau = SoNgau + 1: eRw = 0
B1.Offset(, -1).Value = "Bang" & Str(SoNgau) '<=| Đây là dòng lệnh số '0
6 B1.Offset(-1, -1).Value = -B1.Offset(-1, -1).Value 'Thêm Dòng lệnh 6'
End If
Next B1
C1.Value = "Add " & jJ & " rows"
'Thêm các Dòng Lệnh Còn Lại Vô Đây:'
7 With [A65500].End(xlUp)
8 .Value = -.Value
9 End With
End Sub