简体   繁体   English

范围描述一组非相邻单元格

[英]Range describes a group of non-adjacent cells

My app needs to build a buffer from all the selected cells on a worksheet. 我的应用程序需要从工作表上的所有选定单元格构建缓冲区。 I have it working correctly when the selected cells are all one contiguous group, but if the user selects a group of cells, then holds down the control key and selects other cells that are not contiguous to the first set of cells, the Worksheet's Selected range only gives me information on that first group of cells. 当所选单元格都是一个连续组时,我可以正常工作,但是如果用户选择一组单元格,则按住控制键并选择与第一组单元格不连续的其他单元格,工作表的选定范围只给我关于第一组细胞的信息。

I tried the Range "Next" property, but walking that seems to just return ranges containing cell-by-cell traversal of that first range. 我尝试了Range“Next”属性,但是走路似乎只返回包含第一个范围的逐个单元格遍历的范围。

VBA代码

for i = 1 to selection.Areas.Count : debug.Print selection.areas(i).Address : next

The Address property returns selected ranges (separated by comma) Address属性返回选定的范围(以逗号分隔)

When I select B4 to D10 and then H9 to 016 (by holding ctrl), Selection.Address returns $B$4:$D$10,$H$9:$O$16. 当我选择B4到D10然后选择H9到016(通过按住ctrl)时,Selection.Address返回$ B $ 4:$ D $ 10,$ H $ 9:$ O $ 16。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM