如何使用Excel VBA将单元格值和文本连接在一起? [英] How do I concatenate cell values and text together using Excel VBA?

查看:648
本文介绍了如何使用Excel VBA将单元格值和文本连接在一起?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个重复的任务,我想自动执行,而不是一直使用= Concatenate函数.到目前为止,这是我的代码:

I have a repetitive task I'd like to automate instead of using the =Concatenate function all the time. Here's my code so far:

Cells(2, 5).Value = Cells(2, 1).Value&" - "&Cells(2, 2).Value

不幸的是,这导致出现编译错误:预期:语句结尾"错误,该错误突出显示了-".如何在两个值之间夹住文本-"?

Unfortunately this results in the "Compile error: Expected: end of statement" error, which highlights the " - ". How can I sandwich that text, " - ", between those two values?

推荐答案

Cells(2, 5).Value = Cells(2, 1).Value & " - " & Cells(2, 2).Value

这篇关于如何使用Excel VBA将单元格值和文本连接在一起?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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