公式中的动态列引用
dynamic column reference in formula
我想在最后一列的左侧放置一个公式 3 个单元格。有没有办法做到这一点?也许通过专栏地址?
lc = .Cells(3, Columns.count).End(xlToLeft).Column
.Cells(3, lc + 3).Formula = "=CountCcolor(E3:N" & lrPT & ", " & .Cells(0, lc + 2) & "3)"
此致,
lc + 3
是右边的三列,而不是左边的,但这几乎可以肯定是错字。这应该使您的公式构造消失。
lc = .Cells(3, Columns.count).End(xlToLeft).Column
.Cells(3, lc + 3).Formula = "=CountCcolor(E3:N" & lrPT & ", " & .Cells(3, lc + 2).ADDRESS & ")"
VBA 的 Range.Address property 可以以相对和绝对寻址的各种组合输出单元格引用。我将其保留为默认值(例如绝对值),但我认为它在您的公式中并不重要(单个单元格中的单个公式)。
顺便说一句,如果 N 列中有值,lc + 2
将引用 P3,而不是 O3。
我想在最后一列的左侧放置一个公式 3 个单元格。有没有办法做到这一点?也许通过专栏地址?
lc = .Cells(3, Columns.count).End(xlToLeft).Column
.Cells(3, lc + 3).Formula = "=CountCcolor(E3:N" & lrPT & ", " & .Cells(0, lc + 2) & "3)"
此致,
lc + 3
是右边的三列,而不是左边的,但这几乎可以肯定是错字。这应该使您的公式构造消失。
lc = .Cells(3, Columns.count).End(xlToLeft).Column
.Cells(3, lc + 3).Formula = "=CountCcolor(E3:N" & lrPT & ", " & .Cells(3, lc + 2).ADDRESS & ")"
VBA 的 Range.Address property 可以以相对和绝对寻址的各种组合输出单元格引用。我将其保留为默认值(例如绝对值),但我认为它在您的公式中并不重要(单个单元格中的单个公式)。
顺便说一句,如果 N 列中有值,lc + 2
将引用 P3,而不是 O3。