H
heyhey1994
Guest
- 6/3/17
- 6
- 1
- 3
- 30
Em viết đoạn code thế này mà chạy nó thông báo: next without for. Anh chị nào biết sửa giúp em với ạ
Public Sub chaymm()
Dim i, j, k As Integer
k = WorksheetFunction.counta(Range("A:A")) + 1
For i = 4 To 100
If (Cells(i + 1, 1).Value = Cells(i, 1).Value) And (Cells(i + 1, 2).Value = Cells(i, 2).Value) And (Cells(i + 1, 11).Value > Cells(i, 11).Value) Then
Sheets("Sheet1").Cells(j, 3).Value = (Cells(i + 1, 11).Value)
If (Cells(i + 1, 1).Value = Cells(i, 1).Value) And (Cells(i + 1, 2).Value = Cells(i, 2).Value) And (Cells(i + 1, 11).Value < Cells(i, 11).Value) Then
Sheets("Sheet1").Cells(j, 3).Value = (Cells(i, 11).Value)
If (Cells(i + 1, 1).Value = Cells(i, 1).Value) And (Cells(i + 1, 2).Value <> Cells(i, 2).Value) Then
j = j + 1
Sheets("Sheet1").Cells(j, 1).Value = (Cells(i, 1).Value)
Sheets("Sheet1").Cells(j, 2).Value = (Cells(i, 2).Value)
Sheets("Sheet1").Cells(j, 3).Value = (Cells(i, 11).Value)
If (Cells(i + 1, 1).Value <> Cells(i, 1).Value) And (Cells(i + 1, 2).Value <> Cells(i, 2).Value) Then
j = j + 1
Sheets("Sheet1").Cells(j, 1).Value = (Cells(i, 1).Value)
Sheets("Sheet1").Cells(j, 2).Value = (Cells(i, 2).Value)
Sheets("Sheet1").Cells(j, 3).Value = (Cells(i, 11).Value)
End If
Next i
End Sub
Public Sub chaymm()
Dim i, j, k As Integer
k = WorksheetFunction.counta(Range("A:A")) + 1
For i = 4 To 100
If (Cells(i + 1, 1).Value = Cells(i, 1).Value) And (Cells(i + 1, 2).Value = Cells(i, 2).Value) And (Cells(i + 1, 11).Value > Cells(i, 11).Value) Then
Sheets("Sheet1").Cells(j, 3).Value = (Cells(i + 1, 11).Value)
If (Cells(i + 1, 1).Value = Cells(i, 1).Value) And (Cells(i + 1, 2).Value = Cells(i, 2).Value) And (Cells(i + 1, 11).Value < Cells(i, 11).Value) Then
Sheets("Sheet1").Cells(j, 3).Value = (Cells(i, 11).Value)
If (Cells(i + 1, 1).Value = Cells(i, 1).Value) And (Cells(i + 1, 2).Value <> Cells(i, 2).Value) Then
j = j + 1
Sheets("Sheet1").Cells(j, 1).Value = (Cells(i, 1).Value)
Sheets("Sheet1").Cells(j, 2).Value = (Cells(i, 2).Value)
Sheets("Sheet1").Cells(j, 3).Value = (Cells(i, 11).Value)
If (Cells(i + 1, 1).Value <> Cells(i, 1).Value) And (Cells(i + 1, 2).Value <> Cells(i, 2).Value) Then
j = j + 1
Sheets("Sheet1").Cells(j, 1).Value = (Cells(i, 1).Value)
Sheets("Sheet1").Cells(j, 2).Value = (Cells(i, 2).Value)
Sheets("Sheet1").Cells(j, 3).Value = (Cells(i, 11).Value)
End If
Next i
End Sub