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

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

问题描述

如何获取具有范围地址的范例地址(如$ B $ 4:$ B $ 11)的合并单元格的值在vba中

解决方案

即使真的不鼓励在Excel中使用合并单元格(使用 跨越选择中心 ,如果需要的话),包含价值是左上角的(至少这是表达它的一种方式)。



因此,您可以获得
$ b


  • Range(B4)。值

  • 范围(B4:B11)单元格(1).Value

  • 范围(B4:B11)。单元格(1,1).Value



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



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


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

解决方案

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).

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

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

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天全站免登陆