根据单元格值excel宏插入下面的行 [英] Insert row below based on cell value excel macro
本文介绍了根据单元格值excel宏插入下面的行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
宏代码是:
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
与ActiveSheet
对于R = LastRow到StartRow + 1步骤-1
如果.Cells(R,Col)=0然后
.Cells(R,Col)。 EntireRow.Insert Shift:= xlDown
End If
Next R
End With
Application.ScreenUpdating = True
End Sub
解决方案
编辑以下行:
.Cells(R,Col).EntireRow.Insert Shift:= xlDown
to:
.Cells(R + 1,Col).EntireRow.Insert Shift:= xlDown
Hi Im a totally newbee but eager to learn. I found a macro in this forum at Insert copied row based on cell value. The macro below insert a blank row above any row that has a value of "0" in column E, and it nearly helps me out. Instead of the empty row appears above the row I need it to appear below instead.Can anybody help me?. The macro code is:
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
解决方案
Edit the following line from:
.Cells(R, Col).EntireRow.Insert Shift:=xlDown
to:
.Cells(R+1, Col).EntireRow.Insert Shift:=xlDown
这篇关于根据单元格值excel宏插入下面的行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文