使用Excel中另一列的公式
例如,我会简化这个
我在B列有一个公式是Ax + 2,
例如在B1中,在B2中是A1 + 2,是A2 + 2
我想在列Y中做出一个公式,它反映了B列中的任何公式,但用X代替公式中的A。
例如在Y1中,在Y2中是X1 + 2,是X2 + 2
不pipeB列公式如何,我想Y中的公式反映这些变化。
实际上,如果我可以做类似于= B1.formula.replace(“A”,“X”)的东西,那么就可以完成这项工作。
这可以在顶部的公式栏中完成,还是需要通过macros来完成?
谢谢
这是解决scheme
Sub Button1_Click()Dim s As String
s =范围(“b2”)。公式
Dim res As String res = Replace(s,“A”,“x”)
MsgBox res
结束小组
selectB,复制列,selectY,然后select“粘贴专用”公式才可以完成这项工作
在您的评论之后:
Private Sub Workbook_Open() Range("Y:Y").FormulaR1C1 = Range("B:B").FormulaR1C1 End Sub
将做的工作(macros放在ThisWorkbook)
在你的第二个评论之后
Sub Workbook_Open() On Error GoTo errLbl xlCalc = Application.Calculation Application.Calculation = xlCalculationManual ' stop calculation ' Application.ScreenUpdating = False ' disable screen update ' For Each c In Range("B:B") Range("Y" & c.Row).Formula = Replace(c.Formula, "A", "D") If c.Formula = vbNullString Then Exit For ' stop if "B" has no formula ' Next errLbl: Application.ScreenUpdating = True ' enable screen update ' Application.Calculation = xlCalc ' enable calculation back to where it was ' End Sub