Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/vba/15.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Vba 在列中的2个值之间添加多行_Vba_Excel - Fatal编程技术网

Vba 在列中的2个值之间添加多行

Vba 在列中的2个值之间添加多行,vba,excel,Vba,Excel,我有3000多行数据。我想找到单元格(x)=A和 下一个单元格=B,然后在两个单元格之间添加5个空白行 30.5 30.5 30.5 32.5 32.5 32.5 32.5 42.5 我有下面的代码几乎可以工作,但在行下面留下一个“32.5s” Sub AddRow() Dim Col As Variant Dim BlankRows As Long Dim LastRow As Long Dim R As Long Dim StartRow As L

我有3000多行数据。我想找到单元格(x)=A和 下一个单元格=B,然后在两个单元格之间添加5个空白行

30.5
30.5
30.5
32.5
32.5
32.5
32.5
42.5
我有下面的代码几乎可以工作,但在行下面留下一个“32.5s”

Sub AddRow()

    Dim Col As Variant
    Dim BlankRows As Long
    Dim LastRow As Long
    Dim R As Long
    Dim StartRow As Long

    Col = "K"
    StartRow = 2
    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) = 32.5 And .Cells(R, Col).Offset(1, 0) = 42.5 Then
               .Cells(R, Col).EntireRow.Insert Shift:=xlUp
               .Cells(R, Col).EntireRow.Insert Shift:=xlUp
               .Cells(R, Col).EntireRow.Insert Shift:=xlUp
               .Cells(R, Col).EntireRow.Insert Shift:=xlUp
               .Cells(R, Col).EntireRow.Insert Shift:=xlUp
            End If
        Next R
    End With
    Application.ScreenUpdating = True

End Sub 

差不多了。快速修复:按以下方式执行插入:

.Cells(R + 1, Col).EntireRow.Insert Shift:=xlUp  ' <-- R+1

.Cells(R+1,Col).EntireRow.Insert Shift:=xlUp'几乎在那里。快速修复:按以下方式执行插入:

.Cells(R + 1, Col).EntireRow.Insert Shift:=xlUp  ' <-- R+1

.Cells(R+1,Col).EntireRow.Insert Shift:=xlUp'Schweet!!!A.S.H.感谢您的编辑、回答和建议。我还在努力想办法,所以我很感激。接下来,我将尝试让它在某些列中复制上面的单元格。站在旁边,我猜:)施威特!!!A.S.H.感谢您的编辑、回答和建议。我还在努力想办法,所以我很感激。接下来,我将尝试让它在某些列中复制上面的单元格。我想,站在一边:)