-----------------
Public Sub xx()
Dim i, j, k As Integer
k = 1 'k赋初值
i = InputBox("please input the item num:") '给出总行数信息
For j = 1 To i '循环判断
If Sheets("sheet1").Cells(j, 5).Text = 1 Then '如果第5列的值等于1
Sheets("sheet1").Range(Cells(j, 1), Cells(j, 5)).Copy '复制
Sheets("Sheet2").Range(Cells(k, 1), Cells(k, 5)).Paste Link:=True '粘贴链接
k = k + 1 '表2行号增加
End If
Next
End Sub
-----------
135列复制:
-------------
Public Sub xx1()
Dim i&, j%, k%, m%, n%, A(1 To 3) As Integer
A(1) = 1 '需要复制连接的列
A(2) = 3
A(3) = 5
k = 1 'k赋初值
i = InputBox("please input the item num:") '给出总行数信息
For j = 1 To i '循环判断
If Sheets("sheet1").Cells(j, 5).Text = 1 Then '如果第5列的值等于1
For m = LBound(A) To UBound(A)
Sheets("sheet1").Cells(j, A(m)).Copy '复制
Sheets("Sheet2").Cells(k, m).Paste Link:=True '粘贴链接
Next
k = k + 1 '表2行号增加
End If
Next
End Sub
Range("R2:S"&n&"")改成
Range("R2:S"&n)
wps写VBA,复杂点的VBA容易莫名其妙乱报错,还是excel写VBA好的多。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)