公式上的错误1004

时间:2018-06-07 16:02:08

标签: excel vba excel-vba debugging

当我运行此代码时,我反复收到错误1004

with activecell
.Formula = "=CONCATENATE(" & ActiveCell.Offset(0, -2).Address & "," _
& ":" & "," & ActiveCell.Offset(0, -1).Address & ")"
end with

有没有人知道问题出在哪里?

1 个答案:

答案 0 :(得分:4)

你想要

"=CONCATENATE(" & ActiveCell.Offset(0, -2).Address & ","":""," & ActiveCell.Offset(0, -1).Address & ")"

因为您当前的公式评估为(选择了F4)

=CONCATENATE($D$4,:,$E$4)

错误是错误的。

尝试

Option Explicit
Public Sub test()
    With ActiveCell
        .Formula = "=CONCATENATE(" & .Offset(0, -2).Address & ","":""," & .Offset(0, -1).Address & ")"
    End With
End Sub

具有评估为

的公式
=CONCATENATE($D$4,":",$E$4)

这会在""

周围添加缺失的: