2014-09-03 73 views
-2

我從論壇複製下面的vba代碼以插入新行,其中單元格的值與上面不同。它工作完美,但它只插入1個新行。MS Excel 2007 VBA宏插入三行,其中單元格的值發生變化

我需要插入三個新行。請幫助一些代碼。

VBA

Sub InsertRowAtChangeInValue() 

    Dim lRow As Long 

    For lRow = Cells(Cells.Rows.Count, "L").End(xlUp).Row To 2 Step -1 
    If Cells(lRow, "L") <> Cells(lRow - 1, "L") 
     Then Rows(lRow).EntireRow.Insert 
    Next 

    lRow 

End Sub 
+0

你能與我們共享的代碼嗎? – 2014-09-03 09:53:40

+0

這是代碼{Sub InsertRowAtChangeInValue() Dim lRow As Long For lRow = Cells(Cells.Rows.Count,「L」)。End(xlUp).Row To 2 Step -1 If Cells(lRow,「 (lRow - 1,「L」)Then Row(lRow).EntireRow.Insert Next lRow End Sub } – Kaiser 2014-09-03 10:02:20

回答

1
Sub InsertRowAtChangeInValue() 

    Dim lRow As Long 

    For lRow = Cells(Cells.Rows.Count, "L").End(xlUp).Row To 2 Step -1 
     If Cells(lRow, "L") <> Cells(lRow - 1, "L") Then _ 
      Range(Rows(lRow), Rows(lRow + 2)).EntireRow.Insert 
    Next lRow 

End Sub 
+0

像魔術一樣工作 – Kaiser 2014-09-03 10:38:35

相關問題