vba 根据单元格值在下方插入行
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/24489376/
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 row below based on cell value
提问by user3789695
I found a macro at Insert copied row based on cell value.
我在Insert copyed row based on cell value找到了一个宏。
The macro inserts a blank row above any row that has a value of "0" in column E.
该宏在 E 列中值为“0”的任何行上方插入一个空白行。
Instead of the empty row appearing above, I need it to appear below.
而不是出现上面的空行,我需要它出现在下面。
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 Steven Nelms
Edit the following line from:
编辑以下行:
.Cells(R, Col).EntireRow.Insert Shift:=xlDown
to:
到:
.Cells(R+1, Col).EntireRow.Insert Shift:=xlDown
回答by Alexander Bell
Pertinent to you question, modify a single line in original code: instead of:
与您的问题有关,修改原始代码中的一行:而不是:
.Cells(R, Col).EntireRow.Insert Shift:=xlDown
use this one:
使用这个:
.Cells(R, Col).EntireRow.Insert Shift:=xlUp
Rgds,
Rgds,