Actuarial Outpost
 
Go Back   Actuarial Outpost > Actuarial Discussion Forum > Software & Technology
FlashChat Actuarial Discussion Preliminary Exams CAS/SOA Exams Cyberchat Around the World Suggestions

Entry Level
Actuarial Jobs

Casualty, Health

Pensions
Life, Investments

DW Simpson & Co.
Actuarial
Recruitment
Worldwide

Casualty Jobs
& Property -- Worldwide
Reinsurance,

Insurance, Bureaus & Consulting

Salary Surveys
Life & Health

Pension
Property & Casualty


Reply
 
Thread Tools Display Modes
  #1  
Old 02-07-2005, 02:24 PM
ActuaryToBe ActuaryToBe is offline
Member
 
Join Date: Oct 2004
Posts: 493
Default VLOOKUP in VBA

I am having a problem with the following line of code in VBA:

If Application.WorksheetFunction.VLookup(Cells(i, 26), Range(Cells(4, 3), Cells(lastRCap, 3)), 1, False) = "123" Then

I am getting an error message that says: "Application-defined or object-defined error". Could somebody help me out; I am somewhat of a beginner in using VBA.
Reply With Quote
  #2  
Old 02-07-2005, 02:32 PM
Tyger Tyger is offline
 
Join Date: Mar 2004
Posts: 23
Default

Try using "cell" instead of "cells".

Unless that was just a typo.
Reply With Quote
  #3  
Old 02-07-2005, 02:33 PM
Old Timer's Avatar
Old Timer Old Timer is offline
Member
SOA AAA
 
Join Date: Sep 2001
Location: The Great East
Posts: 1,559
Default

What is the value of lastRcap? Is there really a match? Is the matched value really text or is it numeric?
__________________
Life is chaos personified.
Reply With Quote
  #4  
Old 02-07-2005, 02:36 PM
MathGuy's Avatar
MathGuy MathGuy is offline
Official Speelchecker
CAS AAA
 
Join Date: Oct 2001
Location: Boston-ish
Favorite beer: Panda
Posts: 2,038
Blog Entries: 5
Default

I ran this snippet of code through VBA and it worked just fine. However, you get the error you've described if the variables i and lastRCap are not defined.
__________________
Outposter 3.14 is a generally awesome person, and a servicible approximation to pi.

This message subject to change.
Reply With Quote
  #5  
Old 02-07-2005, 02:45 PM
ActuaryToBe ActuaryToBe is offline
Member
 
Join Date: Oct 2004
Posts: 493
Arrow

lastRCap is the # of rows in the list, and yes, there is really a match that is numeric.

I don't know if it matters, but it is in a for loop, I tried changing Cells to 'Cell' as per Tyger's suggestion but that just gave a compile error.

Here is the whole bit of code I'm using it in:

For i = 2 To lastRSource
If Application.WorksheetFunction.VLookup(Cells(i, 26), Range(Cells(4, 3), Cells(lastRCap, 3)), 1, False) = "123" Then
Range("A1") = 123
End If
Next i
Reply With Quote
  #6  
Old 02-07-2005, 02:47 PM
ActuaryToBe ActuaryToBe is offline
Member
 
Join Date: Oct 2004
Posts: 493
Default

Hmm..I don't think I changed anything, but when I run it now, I am getting an error saying: "Unable to get the VLookup property of the WorksheetFunction class"
Reply With Quote
  #7  
Old 02-07-2005, 03:07 PM
ActuaryToBe ActuaryToBe is offline
Member
 
Join Date: Oct 2004
Posts: 493
Default

Sorry, ignore the last post about the "Unable to get the VLookup property of the WorksheetFunction class" error; that was a result of something I commented out by mistake.
Reply With Quote
  #8  
Old 02-07-2005, 03:28 PM
whisper's Avatar
whisper whisper is online now
Member
CAS
 
Join Date: Jan 2002
Location: Chicago
Favorite beer: Hefewizen
Posts: 26,900
Default

Do you have the Analysis Toolpack VBA addin installed?
Reply With Quote
  #9  
Old 02-07-2005, 03:33 PM
ActuaryToBe ActuaryToBe is offline
Member
 
Join Date: Oct 2004
Posts: 493
Default

Quote:
Originally Posted by whisper
Do you have the Analysis Toolpack VBA addin installed?
Yes, I do.
Reply With Quote
  #10  
Old 02-07-2005, 03:53 PM
whisper's Avatar
whisper whisper is online now
Member
CAS
 
Join Date: Jan 2002
Location: Chicago
Favorite beer: Hefewizen
Posts: 26,900
Default

You need to put in some error handling procedures.

The problem you're getting is when the value you're looking up is not in the vlookup range.

You need an On Error routine.
Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off


All times are GMT -4. The time now is 09:23 AM.


Powered by vBulletin®
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.
*PLEASE NOTE: Posts are not checked for accuracy, and do not
represent the views of the Actuarial Outpost or its sponsors.
Page generated in 0.44520 seconds with 7 queries