Selection

  • Thread starter Thread starter Bob
  • Start date Start date
B

Bob

Hi Everyone:

In excel 2003 VBA, I am writing a sub in a module. Is there a way of
knowing when a selection was made, was it left to right or right to left? I
need to know which column the user clicked first and then dragged the mouse
to create the selection. I think I have to use the ActiveCell.Address
property, is that correct? Thanks for all your help.

Bob
 
You should be able to build whatever final solution you would like to
achieve around this code...

Private Sub Worksheet_SelectionChange(ByVal Target As Range)
Dim StartCell As Range
Dim Direction As String
If Selection.Count > 1 Then
Set StartCell = Range(Split(Selection.Address, ":")(0))
If Selection.Columns.Count > 1 Then
If ActiveCell.Column = StartCell.Column Then
Direction = "Left-to-Right"
Else
Direction = "Right-to-Left"
End If
End If
If Selection.Rows.Count > 1 And Selection.Columns.Count > 1 Then
Direction = Direction & " and "
End If
If Selection.Rows.Count > 1 Then
If ActiveCell.Row = StartCell.Row Then
Direction = Direction & "Top-to-Bottom"
Else
Direction = Direction & "Bottom-to-Top"
End If
End If
MsgBox Direction
End If
End Sub
 
Thank you Rick. That was great.

Bob

Rick Rothstein said:
You should be able to build whatever final solution you would like to
achieve around this code...

Private Sub Worksheet_SelectionChange(ByVal Target As Range)
Dim StartCell As Range
Dim Direction As String
If Selection.Count > 1 Then
Set StartCell = Range(Split(Selection.Address, ":")(0))
If Selection.Columns.Count > 1 Then
If ActiveCell.Column = StartCell.Column Then
Direction = "Left-to-Right"
Else
Direction = "Right-to-Left"
End If
End If
If Selection.Rows.Count > 1 And Selection.Columns.Count > 1 Then
Direction = Direction & " and "
End If
If Selection.Rows.Count > 1 Then
If ActiveCell.Row = StartCell.Row Then
Direction = Direction & "Top-to-Bottom"
Else
Direction = Direction & "Bottom-to-Top"
End If
End If
MsgBox Direction
End If
End Sub
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top