在“风险合作伙伴数据”工作表中包含数据,并在“计算数据”中显示计算内容
如何简化以下代码?
ActiveCell.FormulaR1C1 = _
"=CONCATENATE(RPdata[@[Parish Code]]&"", ""&RPdata[@Parish])"
Range("A2").Select
Selection.AutoFill Destination:=Range("A2:A520"), Type:=xlFillDefault
Range("A2:A520").Select
Columns("A:A").EntireColumn.AutoFit
Range("B2").Select
ActiveCell.FormulaR1C1 = "=RPdata[@[Building ID 1]]"
Range("B2").Select
Selection.AutoFill Destination:=Range("B2:B505")
Range("B2:B505").Select
Range("F2").Select
ActiveCell.FormulaR1C1 = _
"=IF(RPdata[@[Basis of Cover]]=""Demolition"",RPdata[@Demolition],IF(RPdata[@[Basis of Cover]]=""Replacement"",SUM(RPdata[@[Replacement Value]:[Demolition]]), IF(RPdata[@[Basis of Cover]]=""Indemnity"",SUM(RPdata[@[Indemnity Value]:[Indemnity Inflation Value]],RPdata[@[Agreed Value]]))))"
Range("F3").Select
Sheets("Calc Data").Select
Range("F2").Select
Selection.AutoFill Destination:=Range("F2:F505")
Range("F2:F505").Select
我的目标:如果“风险合作伙伴数据”中的数据发生更改,则会在“计算数据”工作表中自动获取。填充所有活动单元格。结束(1xUp)?
不胜感激。
答案 0 :(得分:0)
您没有提供太多背景信息,但这可能会让您入门。
您可以消除所有选择切换和自动填充的内容:
Range("A2:A520").Formula = "=CONCATENATE(RPdata[@[Parish Code]]&"", ""&RPdata[@Parish])"
Range("B2:B505").Formula = "=RPdata[@[Building ID 1]]"
Columns("A:A").EntireColumn.AutoFit
Range("F2:F505").Formula = _
"=IF(RPdata[@[Basis of Cover]]=""Demolition"",RPdata[@Demolition],IF(RPdata[@[Basis of Cover]]=""Replacement"",SUM(RPdata[@[Replacement Value]:[Demolition]]), IF(RPdata[@[Basis of Cover]]=""Indemnity"",SUM(RPdata[@[Indemnity Value]:[Indemnity Inflation Value]],RPdata[@[Agreed Value]]))))"