Steve
Steve

Reputation: 995

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.

Upvotes: 1

Views: 1917

Answers (2)

shahkalpesh
shahkalpesh

Reputation: 33476

VBA Code

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

Upvotes: 3

shahkalpesh
shahkalpesh

Reputation: 33476

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.

Upvotes: 1

Related Questions