如何大量改变excel表格公式中的列引用?

如何大量改变excel表格公式中的列引用?

例如,这个列的公式包含列G(G2,G23,G30等)的参考,我希望大量更改为列H(H2,H23,H33等)。

没有find任何现有的相关问答,也许没有足够的search,提前抱歉和感谢!

点击列A并执行:

插入>列

G将成为列H ,工作表中引用列G中的单元格的任何公式现在将引用列H中的单元格:

之前:

在这里输入图像说明

之后:

在这里输入图像说明

迅速把这个放在一起,replacefunction留下了很多的希望! (很懒,你可能需要改进)

应将R设置到您要更改引用的公式列中。

只是一个概念的certificate。 确保您保存工作簿的副本,如果您testing它。

 Sub Main() Dim R As Range: Set R = ThisWorkbook.Worksheets("Sheet1").Range("$E$1:$E$2") Dim Cell As Range Dim CellPrecedent As Range Dim CellPrecedents As Range Dim Retry As Boolean: Retry = False For Each Cell In R.Cells On Error Resume Next Set CellPrecedents = Cell.Precedents On Error GoTo 0 If CellPrecedents Is Nothing Then ' skip Else For Each CellPrecedent In CellPrecedents If CellPrecedent.Column = 7 Then ' 7 == G Cell.Formula = Replace(Cell.Formula, "G", "H") GoTo Breakout End If Next CellPrecedent End If Breakout: Next Cell If Retry Then Main End Sub 

谢谢你们,没关系,我find了,很简单。 我只是切换到公式视图(公式菜单),select给我的结果列,并用h代替(Ctrl + H)g。 这一切都完成了。 祝你晚上愉快。