VBA将单元格值设置为包含“不工作”的文本

时间:2022-05-13 22:23:33

I'm trying to get a macro to type out a heap of formulae for me. The formula goes something like this:

我想要一个宏为我输入一堆公式。公式是这样的:

=COUNTIF('other_sheet'!A:A,"hello*")

The user can specify A and other_sheet, so I select the cell and then go

用户可以指定一个和other_sheet,因此我选择单元格,然后继续

ActiveCell.Value = "=COUNTIF('" & othercell & "'!" & column & ":" & _
    column & """,hello*"")"

But it keeps giving me errors like:

但它总是给我一些错误,比如:

1004: Object Defined Error

1004:对象定义错误

I have tried using ActiveCell.Text, ActiveCell.Formula etc. and they all don't work.

我试过使用ActiveCell。文本,ActiveCell。公式等等,它们都不起作用。

2 个解决方案

#1


1  

It needs to be ActiveCell.Formula and ", is the wrong way around next to Hello. It should be:

它需要被激活。公式和“,是在你好旁边的错误方式。”应该是:

ActiveCell.Formula= "=COUNTIF('" & othercell & "'!" & column _
    & ":" & column & ",""hello*"")"

#2


0  

Apparently you can only put proper, completed answers into a cell.

显然,你只能把正确的,完整的答案放入一个细胞中。

i.e. if the output turns out to be "=sum(A:A" and a bracket isn't closed, then the application throws an error just as if you typed it in manually.

例如,如果输出结果是“=sum(A:A)”,并且没有关闭括号,那么应用程序就会抛出一个错误,就像您手动输入一样。

#1


1  

It needs to be ActiveCell.Formula and ", is the wrong way around next to Hello. It should be:

它需要被激活。公式和“,是在你好旁边的错误方式。”应该是:

ActiveCell.Formula= "=COUNTIF('" & othercell & "'!" & column _
    & ":" & column & ",""hello*"")"

#2


0  

Apparently you can only put proper, completed answers into a cell.

显然,你只能把正确的,完整的答案放入一个细胞中。

i.e. if the output turns out to be "=sum(A:A" and a bracket isn't closed, then the application throws an error just as if you typed it in manually.

例如,如果输出结果是“=sum(A:A)”,并且没有关闭括号,那么应用程序就会抛出一个错误,就像您手动输入一样。