按你模板规则来做的,测试下吧,有问题请追问
Sub pj()
Dim iRow%, cRow%, i%, cCol%
iRow = [a999999].End(xlUp).Row
cRow = -1
For i = 2 To iRow
cCol = 5
If Cells(i - 1, 1) <> Cells(i, 1) Then
cRow = cRow + 3
Cells(cRow, 4) = "桩号"
Cells(cRow, 5) = Cells(i, 1)
Cells(cRow + 1, 4) = "左偏距/高程"
Cells(cRow + 2, 4) = "右偏距/高程"
If Cells(i, 2) < 0 Then
Cells(cRow + 1, cCol) = Cells(i, 2)
Cells(cRow + 1, cCol + 1) = Cells(i, 3)
ElseIf Cells(i, 2) > 0 Then
Cells(cRow + 2, cCol) = Cells(i, 2)
Cells(cRow + 2, cCol + 1) = Cells(i, 3)
End If
Else
If Cells(i, 2) < 0 Then
cCol = Cells(cRow + 1, 255).End(xlToLeft).Column + 1
Cells(cRow + 1, cCol) = Cells(i, 2)
Cells(cRow + 1, cCol + 1) = Cells(i, 3)
ElseIf Cells(i, 2) > 0 Then
cCol = Cells(cRow + 2, 255).End(xlToLeft).Column + 1
Cells(cRow + 2, cCol) = Cells(i, 2)
Cells(cRow + 2, cCol + 1) = Cells(i, 3)
End If
End If
Next
End Sub