Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Excel Selection Change Event problem

Status
Not open for further replies.

drrocket5292

Technical User
Sep 6, 2005
73
US
I created a little program that uses the selection change event in excel. basically if someone clicks on a cell with data in it in column A then the spreadhseet drills down on that selection and returns a bunch of information based on what the user selected. this works fine except for when a user highlights the entire row instead of clicking on just the cell in Column A. I can error trap and have a msgbox pop up saying not to do that but what i would like to do is when there are multiple cells selected i would like my program to only recognize the cell in the top left of the selection as being selected but I can't figure out how to do that. Any idea what I would have to add to the following lines of code to essentially make that happen?

Private Sub App1_SheetSelectionChange(ByVal sh As Object, ByVal Target As Range)

If Target.Column = 1 And Target.Row >= 4 And Target.Row <= x Then


I've tried using the following line but it errors out saying its an ivalid property assignment:

if target.columns.count > 1 then
target.column = 1
end if


 


Hi,


Code:
Private Sub App1_SheetSelectionChange(ByVal sh As Object, ByVal Target As Range)
   Dim OneCell as range

   Set OneCell = Target.Cells(1,1)

If OneCell.Column = 1 And OneCell.Row >= 4 And OneCell.Row <= x Then
end if

Skip,
[sub]
[glasses] [red][/red]
[tongue][/sub]
 
something like this ?
Private Sub App1_SheetSelectionChange(ByVal sh As Object, ByVal Target As Range)
Dim myRange As Range
If Target.Column = 1 And Target.Row >= 4 And Target.Row <= x Then
Set myRange = Target.Cells(1, 1)
' your stuff with myRange here
End If
End Sub

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ181-2886
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top