Range describes a group of non-contiguous cells

My application needs to create a buffer from all selected cells on a worksheet. I work correctly when the selected cells are one contiguous group, but if the user selects a group of cells then hold down the control key and select other cells that are not adjacent to the first set of cells, the range of selected sheet only gives me information about the first group of cells.

I tried the Range Next property, but walking that seems to only return ranges containing cell-by-cell traversal of that first range.

+1


source to share


2 answers


The Address property returns the selected ranges (comma separated)



When I select B4 - D10 and then H9 - 016 (while holding ctrl), Selection.Address returns $ B $ 4: $ D $ 10, $ H $ 9 :. $ O $ 16

+1


source


VBA code



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

+3


source







All Articles