Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 24
Default Runtime error '1004':

I get the error, "Unable to get VLookup property of the WorksheetFunction
class" for the following sub:

Sub ShowEmpolymentFollowup()
PasswordOff
HideAllSheets
Dim sh1 As Worksheet
Dim sh2 As Worksheet
Dim StudentCount As Integer
Set sh1 = Sheets("Employment Followup")
Set sh2 = Sheets("Student Info")
StudentCount = 3
Sheets("Employment Followup").Visible = True
Sheets("Student Info").Visible = True
For StudentNum = 33 To 550
If Application.WorksheetFunction.VLookup(sh2.Range("B " & StudentNum),
sh2.Range("A33:J550"), 10, False) = 1 Then
sh1.Range("A" & StudentCount).Value = sh2.Range("B" &
StudentNum).Value
StudentCount = (StudentCount + 1)
End If
Next StudentNum
Sheets("Student Info").Visible = False
Sheets("Employment Followup").Select
PasswordOn
End Sub

Please help me fix this. Thank you in advance.
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35,218
Default Runtime error '1004':

application.worksheetfunction.vlookup() will cause a runtime error if there is
no match.

I'd use something like:

dim Res as variant
....

For StudentNum = 33 To 550
res = application.vlookup(sh2.Range("B" & StudentNum), _
sh2.Range("A33:J550"), 10, False)
if iserror(res) then
'what should happen if there is an error
elseif res = 1 then
sh1.Range("A" & StudentCount).Value = sh2.Range("B" & StudentNum).Value
end if
StudentCount = (StudentCount + 1)
Next StudentNum

St@cy wrote:

I get the error, "Unable to get VLookup property of the WorksheetFunction
class" for the following sub:

Sub ShowEmpolymentFollowup()
PasswordOff
HideAllSheets
Dim sh1 As Worksheet
Dim sh2 As Worksheet
Dim StudentCount As Integer
Set sh1 = Sheets("Employment Followup")
Set sh2 = Sheets("Student Info")
StudentCount = 3
Sheets("Employment Followup").Visible = True
Sheets("Student Info").Visible = True
For StudentNum = 33 To 550
If Application.WorksheetFunction.VLookup(sh2.Range("B " & StudentNum),
sh2.Range("A33:J550"), 10, False) = 1 Then
sh1.Range("A" & StudentCount).Value = sh2.Range("B" &
StudentNum).Value
StudentCount = (StudentCount + 1)
End If
Next StudentNum
Sheets("Student Info").Visible = False
Sheets("Employment Followup").Select
PasswordOn
End Sub

Please help me fix this. Thank you in advance.


--

Dave Peterson
Reply
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
Runtime Error 1004 [email protected] Excel Programming 6 April 14th 07 02:14 AM
Uh oh...Runtime error 1004!!!! zenahs[_7_] Excel Programming 0 March 20th 06 05:16 PM
Runtime error 1004 Daniel Excel Programming 2 July 19th 05 04:37 AM
Excel 2003 Macro Error - Runtime error 1004 Cow Excel Discussion (Misc queries) 2 June 7th 05 01:40 PM
Runtime error '1004': Capinvest Excel Programming 2 August 4th 03 07:16 PM


All times are GMT +1. The time now is 08:50 PM.

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"