Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/excel/28.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 插入4行_Vba_Excel - Fatal编程技术网

Vba 插入4行

Vba 插入4行,vba,excel,Vba,Excel,当单元格为第4列时,我尝试插入一行,但第4列的值不相同。出于某种原因,它插入了4行。它只发生在一开始。有什么不对劲吗 谢谢你的帮助 If Cells(j, 4) <> Cells(j - 1, 4) Then Cells(j, 1).EntireRow.Insert j = j + 1 End If 如果单元格(j,4)单元格(j-1,4),则 单元格(j,1).EntireRow.Insert j=j+1 如果结束 这就是您要尝试的吗 Su

当单元格为第4列时,我尝试插入一行,但第4列的值不相同。出于某种原因,它插入了4行。它只发生在一开始。有什么不对劲吗

谢谢你的帮助

If Cells(j, 4) <> Cells(j - 1, 4) Then
        Cells(j, 1).EntireRow.Insert
        j = j + 1
    End If
如果单元格(j,4)单元格(j-1,4),则
单元格(j,1).EntireRow.Insert
j=j+1
如果结束

这就是您要尝试的吗

Sub Sample()
    Dim ws As Worksheet
    Dim lRow As Long, i As Long

    '~~> Change this to the relevant sheet
    Set ws = ThisWorkbook.Sheets("Sheet1")

    With ws
        lRow = .Range("D" & .Rows.Count).End(xlUp).Row

        For i = lRow To 2 Step -1
            If .Cells(i, 4) <> Cells(i - 1, 4) Then .Cells(i, 1).EntireRow.Insert
        Next i
    End With
End Sub
子样本()
将ws设置为工作表
朦胧如长,我如长
“~~>将其更改为相关的工作表
设置ws=ThisWorkbook.Sheets(“Sheet1”)
与ws
lRow=.Range(“D”和.Rows.Count).End(xlUp).Row
对于i=L,请转至第2步-1
如果.Cells(i,4)Cells(i-1,4)那么.Cells(i,1).EntireRow.Insert
接下来我
以
端接头
屏幕截图:


它可能插入4行,因为下一个不同的列来自先前的insertedrow。插入后应跳过一行