excel - 用于连接的 Excel VBA 函数不返回有效的单元格结果(但 debug.print 显示正确的字符串)
问题描述
没有经验的 Stackoverflow 用户,如果需要,请随时将我指向其他论坛或子论坛。
我创建了以下 VBA(然后还在线查看了其他代码示例,它们似乎都遵循相同的逻辑)。我在调试窗口中测试并准确看到我期望的结果(多行字符串)。但是,当我在工作表单元格中键入公式时,我收到 #Value 错误。
- 该函数拼写正确(我实际上是在 Excel 中从公式自动完成中选择它)
- Excel x64 v2108,Win10 x64本地安装
任何想法为什么不使用公式填充回单元格?
Function ConcatCells()
'just to be safe, clear the string
ConcatCells = ""
'Loop and add each cell text with a line break
For Each cell In Selection
ConcatCells = ConcatCells & Chr(13) & cell.Text
Next
'remove the leading line break
ConcatCells = Right(ConcatCells, Len(ConcatCells) - 1)
'is the string actually being created correctly? Yes
Debug.Print ConcatCells
End Function
解决方案
推荐阅读
- wordpress - 在 URL 栏的地址行显示 URL
- c++ - C++ 全局对象定义取决于链接顺序
- c++ - 在 std::tuple 上“迭代”并可以访问所有构造函数
- javascript - 使用单个按钮打开和关闭图片 (JavaScript)
- spring - Spring - 在@EventListener 上分离但附加在@Service 类中的相同实体
- swagger - 注入javascript文件
- wordpress - 网格模板区域项目在特定屏幕尺寸上消失
- node.js - Discord bot setRole 命令只能随机工作
- javascript - 仅显示数组的最后一个版本
- python - 如何定义保存在一个 exe 文件中的绝对路径?