vba怎么交换两行数据?
excel中的两行数据,在不占用其他行的情况下,交换它们的数据?或者,我有300行数据,想交换每隔3行的数据,但只交换两行中前面n个cell的数据
怎么写,谢谢 --------------------编程问答-------------------- 剪切第二行,粘到第一行前面,剪切第一行,粘到第二行的位置、 --------------------编程问答-------------------- 如果表不是很大干脆把整个表读到数组里然后再往表里写
这时候次序就由你掌控了 --------------------编程问答-------------------- 每隔3行?
1 <--> 4
2 <--> 5
3 <--> 6
4 <--> 7
...
这样换?
Sub dd()
Dim c1, c2, maxrow As Long
maxrow = 300
For x = 1 To maxrow - 3
c1 = Sheet1.Cells(x, 1)
c2 = Sheet1.Cells(x, 2)
Sheet1.Cells(x, 1) = Sheet1.Cells(x + 3, 1)
Sheet1.Cells(x, 2) = Sheet1.Cells(x + 3, 2)
Sheet1.Cells(x + 3, 1) = c1
Sheet1.Cells(x + 3, 2) = c2
Next
End Sub --------------------编程问答-------------------- 这样写 运行大概会快点
Sub dd()
Dim c1, c2, maxrow As Long
maxrow = 300
With Sheet1
For x = 1 To maxrow - 3
c1 = .Cells(x, 1)
c2 = .Cells(x, 2)
.Cells(x, 1) = Sheet1.Cells(x + 3, 1)
.Cells(x, 2) = Sheet1.Cells(x + 3, 2)
.Cells(x + 3, 1) = c1
.Cells(x + 3, 2) = c2
Next
End With
End Sub --------------------编程问答-------------------- Sub dd()
Dim c1, c2, maxrow As Long
maxrow = 300
With Sheet1
For x = 1 To maxrow - 3
c1 = .Cells(x, 1)
c2 = .Cells(x, 2)
.Cells(x, 1) = .Cells(x + 3, 1)
.Cells(x, 2) = .Cells(x + 3, 2)
.Cells(x + 3, 1) = c1
.Cells(x + 3, 2) = c2
Next
End With
End Sub
补充:VB , VBA