0
我有四个工作表,我在单元格F2中编写了一个公式,它触发了所有其他的填充。我已经有触发器的私人小组来调用我的程序工作。有没有办法让这个子更有效率?基于另一个工作表的单元格的触发器填充公式
Option Explicit
Sub FillDownFormula_test2()
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
' Filldown a formula for in column of data.
' Assumes a data table with headings in the first row,
' the formula in the second row and is the active cell.
' this one is tested based on set range
' Test results were positive
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
Dim rng As Range, rng2 As Range
Dim rngData As Range
Dim rngFormula As Range, rng2Formula As Range
Dim rowData As Long
Dim colData As Long
Dim wb As Workbook: Set wb = ThisWorkbook
Dim ws As Worksheet, ws2 As Worksheet
Set ws = wb.Sheets("Feuil1")
With ws
' Set the ranges
Set rng = wb.Sheets("Feuil1").Range("F2")
Set rngData = rng.CurrentRegion
' Set the row and column variables
rowData = rngData.CurrentRegion.Rows.Count
colData = rng.Column
' Set the formula range and fill down the formula
Set rngFormula = rngData.Offset(1, colData - 1).Resize(rowData - 1, 1)
rngFormula.FillDown
'G2 is a different formulas but same on every sheets
Set rng2 = wb.Sheets("Feuil1").Range("G2")
' Set the row and column variables
rowData = rngData.CurrentRegion.Rows.Count
colData = rng2.Column
' Set the formula range and fill down the formula
Set rng2Formula = rngData.Offset(1, colData - 1).Resize(rowData - 1, 1)
rng2Formula.FillDown
End With
With ws2
Set rng = wb.Sheets("Feuil2").Range("F2")
Set rngData = rng.CurrentRegion
' Set the row and column variables
rowData = rngData.CurrentRegion.Rows.Count
colData = rng.Column
' Set the formula range and fill down the formula
Set rngFormula = rngData.Offset(1, colData - 1).Resize(rowData - 1, 1)
rngFormula.FillDown
Set rng2 = wb.Sheets("Feuil2").Range("G2")
' Set the row and column variables
rowData = rngData.CurrentRegion.Rows.Count
colData = rng2.Column
' Set the formula range and fill down the formula
Set rng2Formula = rngData.Offset(1, colData - 1).Resize(rowData - 1, 1)
rng2Formula.FillDown
End With
End Sub
最后一个问题:当时做一个范围的效率最高,因此它允许我在做第二个范围之前输入公式。 (我有六个公式filldown)
谢谢
我尝试过,但它看起来像大名单 – Mdh
我不上一个未完成的循环t在这里看到一个循环,我不知道你的意思是什么......另外,尝试使用Debug.Printer来调试它停止的位置 – Maldred
调试将帮助它继续运行?好吧,我要去尝试一下。我不知道它是独立的,但事件触发器永不止步。无论如何,我会尽快回复您 – Mdh