首页 > 解决方案 > Excel VBA插入行加上复制最后一行公式

问题描述

下面的公式只是插入行并更改某些偏移量的颜色。我需要从以前的单元格 H、M、N 中复制公式。有什么想法吗?

Sub button()
LastRow = ActiveSheet.Cells(Rows.Count, "D").End(xlUp).Row
Range("D" & LastRow + 1).EntireRow.Insert
With Range("D" & Rows.Count).End(xlUp).Offset(1)
    .Value = .Offset(-1).Value + 1
    .Offset(, -1).Interior.ColorIndex = 0
    .Offset(, -2).Interior.ColorIndex = 0
    .Offset(, -3).Interior.ColorIndex = 0
End With
End Sub

标签: excel

解决方案


所以现在它正在工作

子 Prideti_produkta()

LastRow = ActiveSheet.Cells(Rows.Count, "D").End(xlUp).Row
Range("D" & LastRow + 1).EntireRow.Insert
Range("H" & LastRow + 1).FillDown
Range("K" & LastRow + 1).FillDown
Range("M" & LastRow + 1).FillDown
Range("N" & LastRow + 1).FillDown

With Range("D" & Rows.Count).End(xlUp).Offset(1)
    .Value = .Offset(-1).Value + 1
    .Offset(, -1).Interior.ColorIndex = 0
    .Offset(, -2).Interior.ColorIndex = 0
    .Offset(, -3).Interior.ColorIndex = 0
End With


End Sub

推荐阅读