使用LastRow复制粘贴范围

我有一个问题,如何从一个特定的范围复制到指定的FirstRow到LastRow,如果从A7向前,直到LastRow行有数据。

如果从A7到LastRow有数据,则H6:J6的公式应该从H7:J7公式粘贴到LastRow。

现在问题是,如果从A7开始,行是空的,它将复制H5:J5的公式。 是否有我可以使用的代码,以便如果A7之前是空的,根本不复制公式? 也许把FirstRow定义为固定的或者其他的东西。

 Sub CopyFormulaIF() Dim myLastRow As Long Dim myCol As Long Dim WB As Workbook Dim WS As Worksheet Set WB = ThisWorkbook Set WS = WB.Sheets("Tabelle1") 'Screen update in 0 seconds Application.ScreenUpdating = 0 With WS myLastRow = .Range("A" & .Rows.Count).End(xlUp).Row End With For myCol = 8 To 10 Cells(6, myCol).Copy Range(Cells(7, myCol), Cells(myLastRow, myCol)).PasteSpecial Paste:=xlFormulas Application.CutCopyMode = False Next myCol End Sub 

样品: 在这里输入图像说明

非常感谢你们

你可以做到这一点

 Option Explicit Sub CopyFormulaIF() Dim myLastRow As Long Dim myCol As Long 'Screen update in 0 seconds Application.ScreenUpdating = 0 With ThisWorkbook.Sheets("Tabelle1") myLastRow = .Range("A" & .Rows.Count).End(xlUp).Row If myLastRow < 7 Then Exit Sub For myCol = 8 To 10 .Range(.Cells(7, myCol), .Cells(myLastRow, myCol)).FormulaR1C1 = .Cells(6, myCol).FormulaR1C1 Next End With End Sub