首页 > 解决方案 > Excel VBA .Formula - 添加对单元格的绝对引用的语法错误

问题描述

我在这个 VBA 代码中有一个语法错误:

students.Cells(studentRow, StartColumn).Formula = _
                        "=If($" & SurnameColumnStr & studentRow & " <> """", if($" & colonnaStr & studentRow & _
                        " <> """",  $" & colonnaStr & " & $" & pointRow & ", 0), """")"

我无法纠正这段代码:($" & colonnaStr & " & $" & pointRow & "就像拥有"$B$3"

我尝试了几种方法都没有运气。任何帮助将非常感激。

标签: excelvba

解决方案


"$B$3"摆脱colonnaStr(列引用)和pointRow(行引用),您需要使用Range.Address.

在你的Formula字符串中使用它:

Range(colonnaStr & pointRow).Address(True, True, xlA1)

结果会给你$B$3

要了解更多信息,请阅读这里


推荐阅读