SoundLogic
New Member
- Joined
- Aug 28, 2009
- Messages
- 3
Good afternoon,
I am getting the error "Compile Error: Invalid Use of Property" whenever a selection change event occurs. I have tried to debug this for a few hours now and I'm simply frustrated
Any clues?
a little background...
I've done a lot of vba coding, but most of it has never been worksheet event based. This code was working then stopped working. It would work again once I restarted so I figured I was clicking something that would send it into a loop. I added the event handler code and it has not worked, at all, since then. The goal is to use cells where nRow = 30 and nCol = 7 as a viewer window (I merged a bunch of cells into this one area) - so it will show the currently selected item. Eventually I want to do something like:
if user selects anything in column 9, load text from a plsql file and displays in the viewer area
if user selects specific cells in an instruction area, it loads information from another worksheet giving them more information on that item (I know I could also use comments for this, but it's not as fun)
if user selects anything else, simply add that item to the viewing area
Here's the code:
Any help would be greatly appreciated!!
I am getting the error "Compile Error: Invalid Use of Property" whenever a selection change event occurs. I have tried to debug this for a few hours now and I'm simply frustrated
Any clues?
a little background...
I've done a lot of vba coding, but most of it has never been worksheet event based. This code was working then stopped working. It would work again once I restarted so I figured I was clicking something that would send it into a loop. I added the event handler code and it has not worked, at all, since then. The goal is to use cells where nRow = 30 and nCol = 7 as a viewer window (I merged a bunch of cells into this one area) - so it will show the currently selected item. Eventually I want to do something like:
if user selects anything in column 9, load text from a plsql file and displays in the viewer area
if user selects specific cells in an instruction area, it loads information from another worksheet giving them more information on that item (I know I could also use comments for this, but it's not as fun)
if user selects anything else, simply add that item to the viewing area
Here's the code:
Code:
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
'prevent Select event triggering again when we extend the selection below
Application.EnableEvents = False
On Error GoTo Handler
Debug.Print Target.Row
Debug.Print Target.Column
Debug.Print Target.Address
Dim nRow As Long
Dim nCol As Long
nRow = Target.Row
nCol = Target.Column
If Target.Row = 1 And Target.Column = 1 Then
Target.Offset(0, 2).Select
Else
If Not IsEmpty(Worksheets("Query").Cells(nRow, nCol).Value) Then
Worksheets("Query").Cells(30, 7).Value = Worksheets("Query").Cells(nRow, nCol).Value
Else
End If
End If
Application.EnableEvents = True
Handler:
Application.EnableEvents = True
Stop
Err.Source
End Sub