简体   繁体   中英

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.

VBA代码

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

The Address property returns selected ranges (separated by comma)

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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