我正在尝试创建一个宏,该宏创建X个使用偏移公式的命名公式。 X将表示sheet1上的数据系列(列)数。这就是我希望如何查找其中一个要创建的内容。
formula = offset($b$2,$a$2,0,$a$3,1)
activeworkbook.names.add Name:="test", Refers to:=formula
但是我要使用do循环,直到i =具有值的列数#。所以这是我最好的拍摄,我确信有很多错误,因为我无法让它运行:
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
所以我的结果基本上是,我得到一个新的名称公式,但参考公式填充整数而不是实际的单元格地址。这是因为我使用的公式调用单元格的值而不是粘贴单元格地址。
任何帮助都会很棒。
答案 0 :(得分: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#来指代单元格的位置。