ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   multi cells selected (https://www.excelbanter.com/excel-programming/406893-multi-cells-selected.html)

greg

multi cells selected
 
Can I tell if multi cells are selected? And can I get each cell?
So if i
click A1
Ctrl+click D1
Ctrl+click G1

Can I get each of these cells?
thanks



Leith Ross[_2_]

multi cells selected
 
On Feb 28, 1:54 pm, "greg" wrote:
Can I tell if multi cells are selected? And can I get each cell?
So if i
click A1
Ctrl+click D1
Ctrl+click G1

Can I get each of these cells?
thanks


Hello Greg,

The Range object has an Areas collection property. If you select a
single cell or a contiguous range of cells then Areas.Count = 1. Here
is a code snippet to display what Ranges you have selected in message
box.

Sub ShowRanges()

Dim Msg As String
Dim Rng As Range

For Each Rng In Selection.Areas
Msg = Msg & Rng.Address & vbCrLf
Next Rng

MsgBox "You selected the following ranges..." & vbCrLf & Msg

End Sub

Sincerely,
Leith Ross

greg

multi cells selected
 
thanks!
that worked

"Leith Ross" wrote in message
...
On Feb 28, 1:54 pm, "greg" wrote:
Can I tell if multi cells are selected? And can I get each cell?
So if i
click A1
Ctrl+click D1
Ctrl+click G1

Can I get each of these cells?
thanks


Hello Greg,

The Range object has an Areas collection property. If you select a
single cell or a contiguous range of cells then Areas.Count = 1. Here
is a code snippet to display what Ranges you have selected in message
box.

Sub ShowRanges()

Dim Msg As String
Dim Rng As Range

For Each Rng In Selection.Areas
Msg = Msg & Rng.Address & vbCrLf
Next Rng

MsgBox "You selected the following ranges..." & vbCrLf & Msg

End Sub

Sincerely,
Leith Ross




Dave Peterson

multi cells selected
 
But you still could get the address of each cell in the selection:

Dim myCell as range
for each mycell in selection.cells
msgbox mycell.address(0,0)
next mycell

and you can check with this kind of code.

if selection.cells.count 1 then
'multiple cells selected
end if

if selection.areas.count 1 then
'multiple areas selected
end if

greg wrote:

Can I tell if multi cells are selected? And can I get each cell?
So if i
click A1
Ctrl+click D1
Ctrl+click G1

Can I get each of these cells?
thanks


--

Dave Peterson


All times are GMT +1. The time now is 12:09 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
ExcelBanter.com