LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default Cell change event

That means the vlookup can't find the value of Range("attn") in the lookup
range.

You need to handle the error

Private Sub Worksheet_Change(ByVal Target As Excel.Range)

Dim company As Range
Dim database As Range
Dim attn As Range

If Target.Address = Range("attn").Address Then
On Error Resume Next
Range("company") = Application.WorksheetFunction _
.VLookup(Range("attn"),Range("database"), 2, False)
End If
On Error goto 0
End Sub

Another problem can be that if these named ranges are not on the worksheet
containing the code, they need to be qualified with the worksheet on which
they are located.
Private Sub Worksheet_Change(ByVal Target As Excel.Range)

Dim company As Range
Dim database As Range
Dim attn As Range
Dim sh1 as Worksheet
Dim sh2 as Worksheet
Set Sh1 = Worksheets("Database")
Set sh2 = Worksheets("Sheet3")

If Target.Address = Range("attn").Address Then
On Error Resume Next
sh2.Range("company") = Application.WorksheetFunction _
.VLookup(Range("attn"),sh1.Range("database"), 2, False)
End If
On Error goto 0
End Sub

as an example.

--
Regards,
Tom Ogilvy



"gig" wrote in message
ups.com...
The error message I keep getting is:

Run time error '1004':

Method 'Range' of object'_worksheet' failed


Thanks





 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
cell change event gvm Excel Worksheet Functions 3 September 20th 05 04:50 AM
cell value change event alinasir Excel Worksheet Functions 1 August 30th 05 10:57 AM
CELL CHANGE EVENT Dan Excel Programming 3 March 3rd 05 10:07 AM
Change Cell from Validated List Not Firing Worksheet Change Event [email protected] Excel Programming 3 October 4th 04 03:00 AM
Cell Change Event Graham[_6_] Excel Programming 8 February 26th 04 04:27 PM


All times are GMT +1. The time now is 08:29 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"