- Tham gia
- 8/6/06
- Bài viết
- 14,611
- Được thích
- 22,931
- Nghề nghiệp
- U80
Nó báo sai tại dòng Min_1, cám ơn các bác nhiều
PHP:
Private Sub CommandButton2_Click()
Dim mRng As Range, Sh As Worksheet, Rng As Range, Clls As Range
Dim Frame As String
Dim eRw As Long, Station As Double, Min_ As Double, Max_ As Double
Sheets("INPUT").Select: eRw = [A65500].End(xlUp).Row
Set Rng = [A2].Resize(eRw - 3, 7): Set Sh = Sheet1
[A1].Resize(65000, 10).Copy Destination:=Sh.[A1] 'vi tri copy'
[M1].Resize(2).Copy Destination:=Sh.[M3] 'vi tri copy tiep theo'
Rng.Sort Key1:=[A2], Order1:=xlAscending, Key2:=[B2], Order2:=1, Header:=xlGuess
For Each Clls In Rng.Cells(2, 1).Resize(eRw)
If Clls.Row = 2 Then
Set mRng = Clls.Offset(6): Frame = Clls.Value
Station = Clls.Offset(, 1).Value
Else
If Clls.Offset(, 1).Value = Station And Clls.Value = Frame Then
Set mRng = Union(mRng, Clls.Offset(, 3))
ElseIf Clls.Offset(, 1).Value <> Station Or _
(Clls.Offset(, 1).Value = Station And Clls.Value <> Frame) Then
With Application.WorksheetFunction
Min_1 = .Min(mRng): Max_1 = .Max(mRng)
End With
If Abs(Min_) > Max_ Then Max_ = Min_
With Sh.[A65500].End(xlUp).Offset(1) 'vi tri paste'
.Value = Frame: .Offset(, 1).Value = Station
.Offset(, 2).Value = Max_
End With
Frame = Clls.Value: Station = Clls.Offset(, 1).Value
Set mRng = Clls.Offset(, 6)
End If
End If
Next Clls
MsgBox mRng.Address
Sh.Select
End Sub