0

我正在尝试创建一个宏来创建 X 数量的使用偏移公式的命名公式。X 将代表 sheet1 上的数据系列(列)的数量。这就是我希望它寻找其中一个被创建的方式。

formula = offset($b$2,$a$2,0,$a$3,1)
activeworkbook.names.add Name:="test", Refers to:=formula

但我将使用 do 循环,直到 i = # of columns with values。所以这是我最好的选择,我敢肯定有很多错误,因为我无法让它运行:

columns = activesheet.countif((1:1),"*"
i = 5 
do until i = columns

'This is where i want to define my static cells location (not value) to be referenced in the formula
    pan = cells(1,2)
    zoom = cells(1,3)

'This is where i want to define my dynamic cells location (not value) based on the current column
    series = cells(2,i)

'This is where i want to create a name formulas specific to each series
    formula = "=offset(" & series & "," & pan & ",0" & zoom & ",1)
    activeworkbook.names.add name:=cells(1,i), refersto:=formula

所以我的结果基本上是,我得到了一个新的名称公式,但参考公式填充了整数,而不是实际的单元格地址。这是因为我使用的是调用单元格值而不是粘贴单元格地址的公式。

任何帮助都会很棒。

4

1 回答 1

0

好的,我知道我做错了什么。当我录制宏时,我没有意识到它放

ActiveWorkbook.Names.Add Name:="Height___zoom", RefersToR1C1:="=Data!R5C1"

现在我可以简单地用

columns = activesheet.countif((1:1),"*"
i = 5 
do until i = columns

pan = "R1C2"
zoom = "R1C3"

series = "R2C" & i

formula = "=offset(" & series & "," & pan & ",0" & zoom & ",1)
activeworkbook.names.add name:=cells(1,i), refersto:=formula

或类似的东西。仍然需要解决一些问题以使其实际运行正确,但我发现该公式使用 R#C# 来引用单元格的位置。

于 2013-03-14T12:09:42.473 回答