ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Selection and Areas (https://www.excelbanter.com/excel-programming/296220-selection-areas.html)

Jac Tremblay

Selection and Areas
 
Hi everyone
I'm trying to find a way to loop on every area in a multiple selection and the help provided is rather concise
' ****
Sub NoMultiAreaSelection(
NumberOfSelectedAreas = Selection.Areas.Coun
If NumberOfSelectedAreas 1 The
MsgBox "You cannot carry out this command on multi-area selections
End I
End Su
' ****
I would like to get some information like the area's address for each area in the current selection. Something like this
****
Sub MultiAreaSelection(
Dim NumberOfSelectedAreas As Integer, intI As Intege
NumberOfSelectedAreas = Selection.Areas.Coun
For intI = 1 To NumberOfSelectedArea
'How can I get each area's address, for example
Next int
End Su
' ****
Another question about Selection
Why, in VBA, when I type "Selection" followed by a dot, I do not get any option suggested. The same as when an object is declared as Object, a too general object

Thanks to anyone who can help.

Chip Pearson

Selection and Areas
 
Jac,

Try something like

Dim Ar As Range
For Each Ar In Selection.Areas
Debug.Print Ar.Address
Next Ar


Why, in VBA, when I type "Selection" followed by a dot, I do

not get any option suggested.

The reason is that Selection is a generic Object, not a specific
type of object. It usually refers to a range of cells, but may
refer to a ChartObject, a Shape, or whatever happens to be
selected at run time. When you are writing code, the editor has
no idea what type of object might be selected, so no Intellisense
is provided.


--
Cordially,
Chip Pearson
Microsoft MVP - Excel
Pearson Software Consulting, LLC
www.cpearson.com



"Jac Tremblay" wrote in
message
...
Hi everyone,
I'm trying to find a way to loop on every area in a multiple

selection and the help provided is rather concise:
' *****
Sub NoMultiAreaSelection()
NumberOfSelectedAreas = Selection.Areas.Count
If NumberOfSelectedAreas 1 Then
MsgBox "You cannot carry out this command on multi-area

selections"
End If
End Sub
' *****
I would like to get some information like the area's address

for each area in the current selection. Something like this:
*****
Sub MultiAreaSelection()
Dim NumberOfSelectedAreas As Integer, intI As Integer
NumberOfSelectedAreas = Selection.Areas.Count
For intI = 1 To NumberOfSelectedAreas
'How can I get each area's address, for example?
Next intI
End Sub
' *****
Another question about Selection:
Why, in VBA, when I type "Selection" followed by a dot, I do

not get any option suggested. The same as when an object is
declared as Object, a too general object?

Thanks to anyone who can help.




Jac Tremblay

Selection and Areas
 
Hi Chip
Thank you very much for this precious help. It works fine for me
For the Selection object, is there a way to restrict the range of objects so that Intellisense is provided? And also, is there a way to check the properties or methods availaible for a specific case of the Selection object, like the selection of worksheet cells
Thanks again for your help.

Tom Ogilvy

Selection and Areas
 
No Jac. Intellisense will not be provided for selection.

You can substitute a specific object and build your code, then go back and
replace it with selection.

or if you know what the selection will be (and you more than likely will),
define a variable to that type

Dim rng as Range


set rng = Selection

' now use rng and you will get the intellisense.

If you are recording your code, then you need to clean it up anyway.

--
Regards,
Tom Ogilvy


"Jac Tremblay" wrote in message
...
Hi Chip,
Thank you very much for this precious help. It works fine for me.
For the Selection object, is there a way to restrict the range of objects

so that Intellisense is provided? And also, is there a way to check the
properties or methods availaible for a specific case of the Selection
object, like the selection of worksheet cells?
Thanks again for your help.




Chris

Selection and Areas
 
You can do something like this..
Dim MyRange as Range 'Do a complie after you type the Dim statemen
Set MyRange = Selection
MyRange.?
Now you can see all the members of a range objec


----- Jac Tremblay wrote: ----

Hi Chip
Thank you very much for this precious help. It works fine for me
For the Selection object, is there a way to restrict the range of objects so that Intellisense is provided? And also, is there a way to check the properties or methods availaible for a specific case of the Selection object, like the selection of worksheet cells
Thanks again for your help.

Tom Ogilvy

Selection and Areas
 
'Do a complie after you type the Dim statement

?? why do a compile ?? That wouldn't be required to the best of my
knowledge.

--
Regards,
Tom Ogilvy

"chris" wrote in message
...
You can do something like this...

Dim MyRange as Range 'Do a complie after you type the Dim statement
Set MyRange = Selection
MyRange.??
Now you can see all the members of a range object


----- Jac Tremblay wrote: -----

Hi Chip,
Thank you very much for this precious help. It works fine for me.
For the Selection object, is there a way to restrict the range of

objects so that Intellisense is provided? And also, is there a way to check
the properties or methods availaible for a specific case of the Selection
object, like the selection of worksheet cells?
Thanks again for your help.




Jac Tremblay

Selection and Areas
 
Thank you Tom
The answer is very usefuf and pertinent.

Jac Tremblay

Selection and Areas
 
Hi chris
Thank you for this precious help. That is all I needed
Jac


All times are GMT +1. The time now is 04:53 AM.

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