Excel VBA自动填充公式从列中的最后一列

我有一个macros在N2单元格中添加公式,并自动填充到表单中的最后一行。

Sub Formulae_to_find_EachFeatureCount() Dim LastRow As Long LastRow = Range("G" & Rows.Count).End(xlUp).Row Range("N2").Select ActiveCell.FormulaR1C1 = "=COUNTIFS(C2,R1C,C1,RC7)" Range("N2").Select Selection.AutoFill Destination:=Range("N2:N" & LastRow), Type:=xlFillDefault ' Range("N2:N10").Select End Sub 

我也可以用下面的代码find最后一列(列名和数字):

  Dim LastColumn As Integer 'Search for any entry, by searching backwards by Columns. LastColumn = Cells.Find(What:="*", After:=[A1], _ SearchOrder:=xlByColumns, _ SearchDirection:=xlPrevious).Column LastCol = Replace(Cells(1, LastColumn).Address(False, False), "1", "") 

现在我想自动填充公式从N列到最后(使用)列。

我想这是你在找什么:

 Sub Formulae_to_find_EachFeatureCount() Dim LastRow As Long LastRow = Range("G" & Rows.Count).End(xlUp).Row Range("N2").Select ActiveCell.FormulaR1C1 = "=COUNTIFS(C2,R1C,C1,RC7)" Range("N2").Select Selection.AutoFill Destination:=Range("N2:N" & LastRow), Type:=xlFillDefault Range("N1:N" & LastRow).Select Selection.AutoFill Destination:=Range("N2:" & lastcol & LastRow), Type:=xlFillDefault End Sub 

注意:但是应该避免使用SELECT