Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/vba/16.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 如果尚未插入行,则插入行_Vba_Excel - Fatal编程技术网

Vba 如果尚未插入行,则插入行

Vba 如果尚未插入行,则插入行,vba,excel,Vba,Excel,我需要在新数据之间插入一个分隔行,并忽略上面已经分隔的现有数据 此代码执行此操作,但每次运行时都会将行添加到空行中 Sub InsertRows() Dim lngLstRow As Long lngLstRow = Range("u" & Rows.Count).End(xlUp).Row For i = lngLstRow To 11 Step -1 If Not IsEmpty(Range("u" & i)) Then If Range("

我需要在新数据之间插入一个分隔行,并忽略上面已经分隔的现有数据

此代码执行此操作,但每次运行时都会将行添加到空行中

Sub InsertRows()
  Dim lngLstRow As Long

  lngLstRow = Range("u" & Rows.Count).End(xlUp).Row
  For i = lngLstRow To 11 Step -1
    If Not IsEmpty(Range("u" & i)) Then
      If Range("u" & i) <> Range("u" & i - 1) Then
        Range("u" & i).EntireRow.Insert
      End If
    End If
  Next
End Sub
子插入行()
昏暗的夜色如长
lngLstRow=Range(“u”和Rows.Count).End(xlUp).Row
对于i=lngLstRow至11步骤-1
如果不是空的(范围(“u”&i)),则
如果范围(“u”和i)范围(“u”和i-1),则
范围(“u”和i).EntireRow.Insert
如果结束
如果结束
下一个
端接头

如果此行或上一行为空,则需要更改代码以不插入额外的行:

Sub InsertRows()
  Dim lngLstRow As Long
  Dim i As Long

  lngLstRow = Range("u" & Rows.Count).End(xlUp).Row
  For i = lngLstRow To 11 Step -1
    If Not (IsEmpty(Range("u" & i)) Or IsEmpty(Range("u" & i - 1))) Then
      If Range("u" & i) <> Range("u" & i - 1) Then
        Range("u" & i).EntireRow.Insert
      End If
    End If
  Next
End Sub
子插入行()
昏暗的夜色如长
我想我会坚持多久
lngLstRow=Range(“u”和Rows.Count).End(xlUp).Row
对于i=lngLstRow至11步骤-1
如果不是(IsEmpty(范围(“u”)和i))或IsEmpty(范围(“u”)和i-1)),则
如果范围(“u”和i)范围(“u”和i-1),则
范围(“u”和i).EntireRow.Insert
如果结束
如果结束
下一个
端接头