简体   繁体   English

如何解决VBA粘贴公式错误1004和下标超出范围

[英]How to solve VBA Paste formula error 1004 and subscript out of range

Trying to paste below formula in excel but it shows试图在excel中粘贴以下公式,但它显示

error 1004错误 1004

Actual Formula:实际公式:

="Fixed Text: Fixed Text="""&C3&""", Fixed Text="""&D3&""", Fixed Text="&E3&", Fixed Text="&F3&", Fixed Text="&", Fixed Text, Fixed Text="&I3&", Fixed Text="&J3&", Fixed Text"""&K3&""";{"&A3&"}"

Tried VBA Code:尝试过的 VBA 代码:

Worksheets (" Fixed Text").Range (A2).Formula="=CHR(34)Fixed Text: Fixed Text=CHR(34)CHR(34)CHR(34)&C3&CHR(34)CHR(34)CHR(34), Fixed Text=CHR(34)CHR(34)CHR(34)&D3&CHR(34)CHR(34)CHR(34), Fixed Text=CHR(34)&E3&CHR(34), Fixed Text=CHR(34)&F3&CHR(34), Fixed Text=CHR(34)&CHR(34), Fixed Text, Fixed Text=CHR(34)&I3&CHR(34), Fixed Text=CHR(34)&J3&CHR(34), Fixed TextCHR(34)CHR(34)CHR(34)&K3&CHR(34)CHR(34)CHR(34);{CHR(34)&A3&CHR(34)}CHR(34)"

Simple procedure to implement formula is as below.实现公式的简单过程如下。

  1. Copy formula from cell and paste it in VBA Editor window.从单元格复制公式并将其粘贴到 VBA 编辑器窗口中。

    ActiveCell.Formula = =A1&""

  2. Select formula text and perform FIND (") & REPLACE ("").选择公式文本并执行 FIND (") & REPLACE ("")。

    ActiveCell.Formula = =A1&""""

在此处输入图片说明

  1. Wrap it with "" finally最后用 "" 包裹

    ActiveCell.Formula = "=A1&"""""

I had written a code for doing this step which is posted on Chandoo Org forums.我已经写了一个代码来执行这一步,它发布在 Chandoo Org 论坛上。 Link is provided below.下面提供了链接。

https://chandoo.org/forum/threads/copy-formula-from-excel-to-clipboard-in-vba-compatible-format.35997/ https://chandoo.org/forum/threads/copy-formula-from-excel-to-clipboard-in-vba-compatible-format.35997/

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM