Know if range has been selected

HuaMin Chen
HuaMin Chen used Ask the Experts™
on
Hi,
ActiveCell.Row

is showing the current selected row. How to know "in advance" if one range is being selected?
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Localization Engineering & Automation
Commented:
Hi,

This depends upon what you need is only "the range" than the below will give the same...

Dim myRange As String
    myRange = Selection.Address 

Open in new window


Thanks,
Shail
Qlemo"Batchelor", Developer and EE Topic Advisor
Top Expert 2015
Commented:
ActiveCell.Row does not show the current selected row, but the row the currently selected cell is in.
As Shailesh showed, you need to observe the Selection object to know if the selection is a single cell, multiple cells, a row, a column, or a combination of many of them.
Top Expert 2016
Commented:
Hi,

pls try something like this

Sub MacroTest()
Set myRange = Range("A:A")
Set inter = Nothing
Set Unio = Union(myRange, Selection)
On Error Resume Next
Set inter = Intersect(myRange, Selection)
On Error GoTo 0
If Unio.Address = myRange.Address Then
    MsgBox "Selection is completely in range"
ElseIf inter Is Nothing Then
    MsgBox "Selection is completely  not in range"
Else
    MsgBox "Selection is partially not in range"
End If
End Sub

Open in new window

Regards
Learn Ruby Fundamentals

This course will introduce you to Ruby, as well as teach you about classes, methods, variables, data structures, loops, enumerable methods, and finishing touches.

HuaMin ChenProblem resolver

Author

Commented:
Many thanks all.

I get
tt523.pngdue to last 2nd line below
    Dim Range0 As String, Row0 As Integer
    Range0 = Selection.Address
   
    If Not (Mid(Range0, 2, 1) > "1" And Mid(Range0, 2, 1) < "9") Then
        Row0 = Active.Row
    End If
HuaMin ChenProblem resolver

Author

Commented:
Why?
ste5anSenior Developer

Commented:
In advance? np-hard.

What is your actual problem?
HuaMin ChenProblem resolver

Author

Commented:
Please omit last question in above.

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial