从vba中的单元格地址获取excel合并单元格的值 [英] Get value of a merged cell of an excel from its cell address in vba

查看:77
本文介绍了从vba中的单元格地址获取excel合并单元格的值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何在vba中获取范围地址为$B$4:$B$11"的excel的合并单元格的值

How to get the value of a merged cell of an excel having range address like "$B$4:$B$11" in vba

推荐答案

即使真的不鼓励在 Excel 中使用合并单元格(使用 Center Across Selection 例如,如果需要),包含"值的单元格是左上角(至少,这是一种表达方式).

Even if it is really discouraged to use merge cells in Excel (use Center Across Selection for instance if needed), the cell that "contains" the value is the one on the top left (at least, that's a way to express it).

因此,您可以通过多种方式获取B4:B11范围内合并单元格的值:

Hence, you can get the value of merged cells in range B4:B11 in several ways:

  • Range("B4").Value
  • Range("B4:B11").Cells(1).Value
  • Range("B4:B11").Cells(1,1).Value

您还可以注意到,所有其他单元格中都没有任何值.调试时可以看到值为empty.

You can also note that all the other cells have no value in them. While debugging, you can see that the value is empty.

另请注意,Range("B4:B11").Value 将不起作用(如果您尝试 Debug.Print 它,则会引发执行错误编号 13)因为它返回一个数组.

Also note that Range("B4:B11").Value won't work (raises an execution error number 13 if you try to Debug.Print it) because it returns an array.

这篇关于从vba中的单元格地址获取excel合并单元格的值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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