Excel中VBA的一个小应用问题,请教大家,请大家指点!

2024-12-16 06:52:07
推荐回答(3个)
回答1:

Sub ddd()
Dim m,n as integer
cells(1,3)=cells(1,1)
n=1
For m= 1 To Range("A65535").End(xlUp).Row-1
If Cells(m+1, 1) <> Cells(m, 2) + 1 Then
n=n+1
Cells(n, 4) = Cells(m, 2)
Cells(n-1,3) = Cells(m+1, 1)
End If
Next
End Sub

回答2:

Sub ls()
Dim i, n As Integer
Range("C1").Value = Range("A1").Value
i = 1
n = 1
Do While Range("A" & i).Value <> ""
If Range("A" & i + 1).Value <> Range("B" & i).Value + 1 Then
Range("D" & n).Value = Range("B" & i).Value
Range("C" & n + 1).Value = Range("A" & i + 1).Value
n = n + 1
End If
i = i + 1
Loop
End Sub

回答3:

Sub ChkData()
Dim ra, rd, MaxRow As Long
MaxRow = Range("A" & Rows.Count).End(xlUp).Row
Range("C1:D" & Rows.Count).ClearContents
Range("C1") = Range("A1")
rd = 1
For ra = 2 To MaxRow
If Cells(ra, 1) <> Cells(ra - 1, 2) + 1 Then
Cells(rd, 4) = Cells(ra - 1, 2)
Cells(rd + 1, 3) = Cells(ra, 1)
rd = rd + 1
End If
Next ra
End Sub