View Single Post
  #6   Report Post  
Posted to microsoft.public.excel.misc
Rick Rothstein \(MVP - VB\)[_636_] Rick Rothstein \(MVP - VB\)[_636_] is offline
external usenet poster
 
Posts: 1
Default What is wrong with this code?

It would probably help if you post the code you have now, after making those
changes, so we can see exactly what you are now working with.

Rick


"Ayo" wrote in message
...
Thanks Dave for the advise. I made the changes you suggested but I'm still
not getting and result or reaction from th e code. Nothing is happening,
at
all.

"Dave Peterson" wrote:

I'd stay away from application.worksheetfunction. If there is no match,
you'll
get a runtime error.

And you have an extra "End If" in your code. That "If .count 1 ..." is
a
single line. It doesn't need and can't have the "End If" line.

And it's probably not a good idea to leave the sub with .screenupdating
turned
off. Excel/VBA is pretty forgiving, but if I turned something off, I'll
want to
turn it on.

But it doesn't look like there's anything that needs to be hidden. I'd
remove
those .screenupdating lines.


Private Sub Worksheet_SelectionChange(ByVal Target As Range)
Dim RF_Table As Range
Dim RF As Range

Set RF_Table = Worksheets("Sheet3").Range("H2:J5").Cells
Set RF = Me.Range("P4:P2000")

With Target
If .Count 1 Then Exit Sub
If Not Intersect(RF, .Cells) Is Nothing Then
If Not IsEmpty(Target) Then
Application.EnableEvents = False
With .Offset(0, 1)
.Value = Application.VLookup(Target, RF_Table, 2,
False)
End With
Application.EnableEvents = True
End If
End If
End With

End Sub

Ayo wrote:

Private Sub Worksheet_SelectionChange(ByVal Target As Range)
Dim RF_Table As Range, RF As Range

Set RF_Table = Worksheets("Sheet3").Range("H2:J5").Cells
Set RF = Range("P4:P2000")
Application.ScreenUpdating = False
With Target
If .Count 1 Then Exit Sub
If Not Intersect(RF, .Cells) Is Nothing Then
If Not IsEmpty(Target) Then
Application.EnableEvents = False
With .Offset(0, 1)
.Value =
Application.WorksheetFunction.VLookup(Target, RF_Table, 2, False)
End With
Application.EnableEvents = True
End If
End If
End If
End With
End Sub


--

Dave Peterson