![](/img/trans.png)
[英]How to automatically insert a copied row after a specific value in a cell with VBA
[英]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.