我有数学等式,我在 Accrued Expenses
的表格" Range("E7")
" 中执行。该公式打算循环直到C列中的 lastrow 两个关键表是"开始页面" 和"应计费用" 。
问题是我无法进入VBA代码。它使用Excel宏录制器工作,但它不会有效维护。我的等式和代码如下。
=('Accrued Expenses'!C7*'Start page'!$F$5)/'Start page'!$F$13*'Accrued Expenses'!D7
在 Excel刻录机代码中并使用循环:
Option Explicit
Sub Calculating_Accruedexpense()
Sheets("Accrued Expenses").Select
Dim LastRow As Long
LastRow = ActiveSheet.Range("C" & Rows.Count).End(xlUp).row
Range("E7").Select
Do Until ActiveCell.row = LastRow + 1
If IsEmpty(ActiveCell) Then
ActiveCell.FormulaR1C1 = _
"=('Accrued Expenses'!RC[-2]*'Start page'!R5C6)/'Start page'!R13C6*'Accrued Expenses'!RC[-1]"
End If
ActiveCell.Offset(1, 0).Select
Loop
End Sub
Excel Recorder行:
ActiveCell.FormulaR1C1 = _
"=('Accrued Expenses'!RC[-2]*'Start page'!R5C6)/'Start page'!R13C6*'Accrued Expenses'!RC[-1]"
答案 0 :(得分:1)
试试这个:
Sub Calculating_AccruedExpense()
Dim lastRow As Long, cl As Range
lastRow = Worksheets("Accrued Expenses").Range("C" & Rows.Count).End(xlUp).Row
For Each cl In Range("E7:E" & lastRow)
If IsEmpty(cl) Then
cl = (cl.Offset(0, -1) * Worksheets("Start page").Range("F5")) / Worksheets("Start page").Range("F13") * cl.Offset(0, -2)
End If
Next cl
End Sub