[英]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.