vba 根据单元格值插入复制的行
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/16513654/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Insert copied row based on cell value
提问by nofunsally
The vba code below (modified from here) will insert a blank row above any row that has a value of "0" in column E. Instead of inserting a blank row, is there a way to copy the row with "0" and insert it above itself? Can this vba code be modified to do this?
下面的 vba 代码(从此处修改)将在 E 列中值为“0”的任何行上方插入一个空白行。有没有办法复制带有“0”的行并插入,而不是插入一个空白行它高于自身?可以修改此 vba 代码以执行此操作吗?
Sub BlankLine()
Dim Col As Variant
Dim BlankRows As Long
Dim LastRow As Long
Dim R As Long
Dim StartRow As Long
Col = "E"
StartRow = 1
BlankRows = 1
LastRow = Cells(Rows.Count, Col).End(xlUp).Row
Application.ScreenUpdating = False
With ActiveSheet
For R = LastRow To StartRow + 1 Step -1
If .Cells(R, Col) = "0" Then
.Cells(R, Col).EntireRow.Insert Shift:=xlDown
End If
Next R
End With
Application.ScreenUpdating = True
End Sub
回答by chris neilsen
Just add this line
只需添加这一行
.Cells(R, Col).EntireRow.Copy
before your .Insert
line
在你的.Insert
线路之前