Professional Documents
Culture Documents
Call sohieu
Call ghicongthuc
Call fillcongthuc
Application.ScreenUpdating = False
Range("S2:W3").Select
With Selection.Font
.Color = -16776961
End With
Selection.Font.Bold = True
With Selection
.HorizontalAlignment = xlCenter
End With
Columns("S:T").Select
Columns("S:T").Select
Selection.NumberFormat = "General"
With Selection
.HorizontalAlignment = xlCenter
End With
Range("S4").Formula = "=INDEX(A:A,MATCH(R4,C:C,0))"
Range("T4").Formula = "=INDEX(B:B,MATCH(R4,C:C,0))"
Range("S4:T4").Select
Range(Selection, Selection.End(xlDown)).Select
Selection.FillDown
Columns("S:T").Select
Selection.Copy
Range("S1").Select
:=False, Transpose:=False
Application.CutCopyMode = False
Range("A1").Select
Application.ScreenUpdating = True
End Sub
Sub sohieu()
Application.ScreenUpdating = False
Columns("R:R").Select
Selection.Clear
Range("C4").Select
Range(Selection, Selection.End(xlDown)).Select
Selection.Copy
Range("R4").Select
ActiveSheet.Paste
Application.CutCopyMode = False
End Sub
Application.Volatile
TTF = Evaluate(Ref)
End Function
Sub ghicongthuc()
Application.ScreenUpdating = False
' Ghi cong thuc
Range("S2").Formula = "Step"
Range("T2").Formula = "Begin"
Range("V2").Formula = "Mid"
Range("X2").Formula = "End"
Range("Y2").Formula = "V2"
Range("Z2").Formula = "V2"
Range("AA2").Formula = "T"
Range("AB2").Formula = "T"
Range("AC2").Formula = "M3"
Range("AD2").Formula = "M3"
Range("AE2").Formula = "M3"
Range("AF2").Formula = "M1-1"
Range("AG2").Formula = "M2-2"
Range("AH2").Formula = "M3-3"
Range("Y3").Formula = "=MATCH(Y2,2:2,0)"
Range("Z3").Formula = "Value"
Range("AA3").Formula = "=MATCH(AA2,2:2,0)"
Range("AB3").Formula = "Value"
Range("AC3").Formula = "=MATCH(AC2,2:2,0)"
Range("AD3").Formula = "=MATCH(AD2,2:2,0)"
Range("AE3").Formula = "=MATCH(AE2,2:2,0)"
Range("AF3").Formula = "Value"
Range("AG3").Formula = "Value"
Range("AH3").Formula = "Value"
Range("S4").Formula = "=COUNTIF(C:C,R4)"
Range("T4").Formula = "4"
Range("U4").Formula = "=ROUNDDOWN((V4-T4)/2,0)+T4"
Range("V4").Formula = "=T4+S4/2-1"
Range("W4").Formula = "=ROUNDDOWN((X4-V4)/2,0)+V4"
Range("X4").Formula = "=T4+S4-1"
Range("Y4").Formula =
"=CONCATENATE(""MAX(MAX("",ADDRESS(T4,$Y$3,4),"":"",ADDRESS(X4,$Y$3,4),""),ABS(MIN("",ADDRE
SS(T4,$Y$3,4),"":"",ADDRESS(X4,$Y$3,4),"")))"")"
Range("Z4").Formula = "=TTF(Y4)"
Range("AA4").Formula =
"=CONCATENATE(""MAX(MAX("",ADDRESS(T4,$AA$3,4),"":"",ADDRESS(X4,$AA$3,4),""),ABS(MIN("",AD
DRESS(T4,$AA$3,4),"":"",ADDRESS(X4,$AA$3,4),"")))"")"
Range("AB4").Formula = "=TTF(AA4)"
Range("AC4").Formula =
"=CONCATENATE(""MIN(MIN("",ADDRESS(T4,$AC$3,4),"":"",ADDRESS(U4,$AC$3,4),""),MIN("",ADDRESS
(V4,$AC$3,4),"":"",ADDRESS(W4,$AC$3,4),""))"")"
Range("AD4").Formula =
"=CONCATENATE(""MAX("",ADDRESS(T4,$AD$3,4),"":"",ADDRESS(X4,$AD$3,4),"")"")"
Range("AE4").Formula =
"=CONCATENATE(""MIN(MIN("",ADDRESS(U4,$AC$3,4),"":"",ADDRESS(V4,$AC$3,4),""),MIN("",ADDRESS
(W4,$AC$3,4),"":"",ADDRESS(X4,$AC$3,4),""))"")"
Range("AF4").Formula = "=TTF(AC4)"
Range("AG4").Formula = "=TTF(AD4)"
Range("AH4").Formula = "=TTF(AE4)"
Range("T5").Formula = "=T4+S4"
Application.ScreenUpdating = True
End Sub
Sub fillcongthuc()
Application.ScreenUpdating = False
Range("S4").Select
Range(Selection, Selection.End(xlDown)).Select
Selection.FillDown
Range("T5").Select
Range(Selection, Selection.End(xlDown)).Select
Selection.FillDown
Range("U4:AH4").Select
Range(Selection, Selection.End(xlDown)).Select
Selection.FillDown
' Copy lai cong thuc va Paste value de bao ve du lieu
Columns("R:AH").Select
Selection.Copy
Range("R1").Select
:=False, Transpose:=False
Columns("S:Y").Select
Application.CutCopyMode = False
Selection.Delete Shift:=xlToLeft
Columns("T:T").Select
Selection.Delete Shift:=xlToLeft
Columns("U:W").Select
Selection.Delete Shift:=xlToLeft
Application.ScreenUpdating = True
End Sub