簡體   English   中英

根據單元格值插入復制的行

[英]Insert copied row based on cell value

下面的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

只需添加此行

.Cells(R, Col).EntireRow.Copy

在您的.Insert行之前

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM