[英]Filling columns with formula based on another Cell
我目前正在根據用戶表單將公式發送到K&L列。 它根據列G的輸入發送公式。 我想僅在G中包含值的情況下才將公式發送到K和L列。 誰能幫我?
'Sets Columns K & L to Method 6 Formula and looks for last populated row in the Nominal Column (G)
LastRow = Range("G" & Rows.Count).End(xlUp).Row
Range("K7").Formula = "=M7+(Q7*(1.04-EXP(0.38*(LN(P7))-0.54)))"
Range("L7").Formula = "=N7-(Q7*(1.04-EXP(0.38*(LN(P7))-0.54)))"
If LastRow = 7 Then
Else
Range("K7").AutoFill Destination:=Range("K7:K" & LastRow)
Range("L7").AutoFill Destination:=Range("L7:L" & LastRow)
End If
如果您的意思是僅在G具有至少一個非空白單元格的情況下運行代碼,則可以使用此代碼。 您可以一次將公式應用於整個范圍。
Sub x()
Dim LastRow As Long
LastRow = Range("G" & Rows.Count).End(xlUp).Row
Range("K7:K" & LastRow).Formula = "=IF(G7="""", """",M7+(Q7*(1.04-EXP(0.38*(LN(P7))-0.54))))"
Range("L7:L" & LastRow).Formula = "=IF(G7="""", """",N7-(Q7*(1.04-EXP(0.38*(LN(P7))-0.54))))"
End Sub
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.