![]() |
Selection
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 |
Selection
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 -- Rick (MVP - Excel) "Bob" wrote in message ... 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 |
Selection
Thank you Rick. That was great.
Bob "Rick Rothstein" wrote in message ... 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 -- Rick (MVP - Excel) "Bob" wrote in message ... 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 |
All times are GMT +1. The time now is 05:55 PM. |
Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com