根据单元格值excel宏插入下面的行 [英] Insert row below based on cell value excel macro

查看:112
本文介绍了根据单元格值excel宏插入下面的行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是一个全新的,但渴望学习。我在此论坛中发现了一个宏,请插入复制的行单元格值。下面的宏在列E中的任何行之上插入一个空值,值为0,几乎可以帮助我。而不是空行出现在行上面我需要它出现在下面。任何人都可以帮助我吗?
宏代码是:

  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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆