如何解决VBA粘贴公式错误1004和下标超出范围 [英] How to solve VBA Paste formula error 1004 and subscript out of range

查看:57
本文介绍了如何解决VBA粘贴公式错误1004和下标超出范围的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

尝试在excel中粘贴以下公式,但显示

Trying to paste below formula in excel but it shows

错误1004

实际公式:

="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&"}"

尝试过的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. 从单元格复制公式并将其粘贴到"VBA编辑器"窗口中.

  1. Copy formula from cell and paste it in VBA Editor window.

ActiveCell.Formula = = A1&"

选择公式文本并执行FIND()& REPLACE(").

Select formula text and perform FIND (") & REPLACE ("").

ActiveCell.Formula = = A1&""

  1. 最后用"换行

  1. Wrap it with "" finally

ActiveCell.Formula ="= A1&"""

我已经编写了执行此步骤的代码,该代码已发布在Chandoo Org论坛上.链接在下面提供.

I had written a code for doing this step which is posted on Chandoo Org forums. Link is provided below.

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

这篇关于如何解决VBA粘贴公式错误1004和下标超出范围的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆