我必须在excel文件中只保留某些行。 基本上当我有 1 2 3 4 五 6 7 8 9 10 我必须保留行号:1,4,7,10,我必须删除所有其他行 我该怎么办?
更新代码尝试
Sub Macro1() ' '
Range("A1").Select
Dim rng As Range
Dim InputRng As Range
Set InputRng = Application.Selection
Set InputRng = Application.InputBox("Range :", xTitleId, InputRng.Address, Type:=8)
Application.ScreenUpdating = False
For i = 1 To InputRng.Rows.Count
ActiveCell.Offset(1, 0).Select
ActiveCell.EntireRow.Delete
ActiveCell.EntireRow.Delete
Next
Application.ScreenUpdating = True
End Sub
答案 0 :(得分:0)
尝试此操作假设您的工作表的代码名称为Sheet1和Sheet2:
Sub CopyRows()
With Sheet1
.Range("1:1,4:4,7:7,10:10").Copy
Sheet2.Range("A1").PasteSpecial
.Cells.Delete
Sheet2.Range("1:4").Copy .Range("A1")
End With
End Sub