Sub FIXPAY()
Dim LastCol As Long, LastRow As Long, s2 As Worksheet
Set s2 = Sheets("Analysis")
s2.Select
Range("A2").Select
Range(Selection, Selection.End(xlToRight)).Copy
s2.Range("A" & Rows.Count).End(xlUp).Offset(2, 0).PasteSpecial xlPasteAll
'*Copy the table header from 1st table and paste it to the second empty row.*
Range("A3:C3").Select
Range(Selection, Selection.End(xlDown)).Copy
s2.Range("A" & Rows.Count).End(xlUp).Offset(1, 0).Select
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
Application.CutCopyMode = False
'*Copy from A3:C3 to the last filled row and paste it to the row right below
the heading.*
s2.Range("D" & Rows.Count).End(xlUp).Offset(1, 0).FormulaR1C1 = _
"=INDIRECT(""'""&RC1&""'!""&ADDRESS(ROW(R73C[-2]),COLUMN(R73C[-2])))"
'*Put the above formula in the D Column right below the heading*
问题出在这里。如何用动态范围替换下面的行,这样它就会自动填充D列中的数据
s2.Range("D" & Rows.Count).End(xlUp).Offset(1, 0).FormulaR1C1 = _
"=INDIRECT(""'""&RC1&""'!""&ADDRESS(ROW(R73C[-2]),COLUMN(R73C[-2])))"
s2.Range("D15").AutoFill destination:=Range("D15:D" & Range("A15").End(xlDown).Row)
LastCol = Cells(14, Columns.Count).End(xlToLeft).Column
LastRow = Range("A" & Rows.Count).End(xlUp).Row
Range("D15", Cells(LastRow, LastCol)).FormulaR1C1 = Range("D15").FormulaR1C1
End Sub
有人可以帮我制作完全动态的代码吗?请注意,我在这里引用了第15行,因为我的第二个表的标题是在第14行,因此D15中的公式将被复制到最后一个填充行和最后一个填充列。