如果A列%上有C后面一样的如A列T03C.0118,T18C.0118和T05C.0115,T08C.0115,就把%以下它们相同后面对应坐标,放在前面坐标前面,谢谢!帮忙改写一下Vba!!我不能运行这两个代码,因为A列数据太多了就如F列,结果如G列,谢谢!!!
Sub test()
Dim i As Long, j As Long, k As Long
Dim x As Long, y As Long, z As Long
Dim s1 As String, s2 As String
Application.ScreenUpdating = False
z = Range("a:a").Find("%").Row
For i = 1 To z - 2
For j = i + 1 To z - 1
If Right(Trim(Cells(i, 1)), 6) = Right(Trim(Cells(j, 1)), 6) Then
s1 = "T" & Val(Mid(Cells(i, 1), 2, 2))
s2 = "T" & Val(Mid(Cells(j, 1), 2, 2))
x = Range("a:a").Find(s2, , , xlWhole).Row
y = x
Do
y = y + 1
Loop Until Len(Trim(Cells(y, 1))) < 4
Range(Cells(x, 1), Cells(y - 1, 1)).Cut
Range("a:a").Find(s1, , , xlWhole).Insert shift:=xlDown
Exit For
End If
Next
Next
Application.ScreenUpdating = True
End Sub
Sub zhengli()
Dim i As Long, j As Long, k As Long
Dim x As Long, y As Long, z As Long
Dim s1 As String, s2 As String
Application.ScreenUpdating = False
Application.Calculation = xlCalculationManual
z = Range("a:a").Find("%").Row
For i = 1 To z - 2
For j = i + 1 To z - 1
If Right(Trim(Cells(i, 1)), 6) = Right(Trim(Cells(j, 1)), 6) Then
If Cells(j, 5) <> "标识孔" Then
s1 = "T" & Val(Mid(Cells(i, 1), 2, 2))
s2 = "T" & Val(Mid(Cells(j, 1), 2, 2))
x = Range("a:a").Find(s2, , , xlWhole).Row
y = x
Do
y = y + 1
Loop Until Len(Trim(Cells(y, 1))) < 4
Range(Cells(x, 1), Cells(y - 1, 1)).Cut
Range("a:a").Find(s1, , , xlWhole).Insert shift:=xlDown
Exit For
End If
End If
Next
Next
Application.Calculation = xlCalculationAutomatic
Application.ScreenUpdating = True
End Sub
本帖最后由 hwc2ycy 于 2012-11-25 11:45 编辑
(, 下载次数: 0)
|