heyhey1994
Thành viên chính thức


- Tham gia
- 16/3/17
- Bài viết
- 78
- Được thích
- 17
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 k
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 k
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