Know if range has been selected


is showing the current selected row. How to know "in advance" if one range is being selected?
LVL 12
HuaMin ChenProblem resolverAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Shailesh ShindeLocalization Engineering & AutomationCommented:

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


Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Qlemo"Batchelor", Developer and EE Topic AdvisorCommented:
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.

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"
    MsgBox "Selection is partially not in range"
End If
End Sub

Open in new window

OWASP: Threats Fundamentals

Learn the top ten threats that are present in modern web-application development and how to protect your business from them.

HuaMin ChenProblem resolverAuthor 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 resolverAuthor Commented:
ste5anSenior DeveloperCommented:
In advance? np-hard.

What is your actual problem?
HuaMin ChenProblem resolverAuthor Commented:
Please omit last question in above.
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft Excel

From novice to tech pro — start learning today.