[英]How to use activecell row and column in VBA function with filldown?
[英]How to Filldown activecell in vba
有人可以帮我吗? 假设I4:I
是我的Lastrow,G中的Activecell将填写公式。
Dim Lastrowzxc As Long
Lastrowzxc = Range("I4").CurrentRegion.Rows.Count
Range("G" & Rows.Count).End(xlUp).Offset(1).Select
ActiveCell.FormulaR1C1 = "=IF(RC[2]<0,""40"",""50"")"
Selection.AutoFill Destination:=Range(ActiveCell.Address & Lastrowzxc)
自动填充的“范围”中的地址不正确。 这可能有效,但这远非完美(只是让您前进的起点):
Dim Lastrowzxc As Long
Lastrowzxc = Range("I4").CurrentRegion.Rows.Count
Range("G" & Rows.Count).End(xlUp).Offset(1).Select
ActiveCell.FormulaR1C1 = "=IF(RC[2]<0,""40"",""50"")"
Selection.AutoFill Destination:=Range(Cells(2, 7), Cells(Lastrowzxc, ActiveCell.Column))
假设I4:I20
是要填充的范围,并且G4
包含公式,这是您应该执行的操作:
Range("I4:I20").FormulaR1C1 = Range("G4").FormulaR1C1
试试这个对我有用:
Dim Lastrowzxc As Long
Lastrowzxc = ActiveSheet.Range("I4").currentRegion.Rows.Count
Range("G" & ActiveSheet.Rows.count).End(xlUp).Offset(1).Select
Selection.FormulaR1C1 = "=IF(RC[2]<0,""40"",""50"")"
Selection.AutoFill Destination:=Range(Range(ActiveCell.Address), Cells(Lastrowzxc, ActiveCell.Column))
为什么要麻烦选择范围? 这是不好的做法。
我不太了解您的目标是什么,因为您正在选择col G中最后一个单元格下面的单元格。我想您想从col G的最后一行开始,直到col I的最后一行? 如果是这样的话..:
With Workbooks("REFERENCE").Sheets("REFERENCE")
LastrowI = .Cells(.Rows.Count, "I").End(xlUp).Row
LastrowG = .Cells(.Rows.Count, "G").End(xlUp).Row
.Range("G" & LastrowG).FormulaR1C1 = "=IF(RC[2]<0,""40"",""50"")" 'change Range if necessary
.Range("G" & LastrowG).FormulaR1C1.AutoFill Destination:= .Range("G" & LastrowG & ":G" & LastrowI)
End With
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.