Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2
Default VLookup problem

I have three workbooks - one from which I'm running by VBA code, one workbook
with data and a third workbook with a table of charges. I want to use the
value of a program code field from the database and find that same value in
the table of charges. For instance, one value from the database program code
field is ASC. I want to look for that value in the first column of the table
of charges and return that value, if it's found. Both fields are set to text
using the format cells function. The table is sorted by ascending program
codes.

In VBA, my code is as follows:

Dim oCell as Object
Dim tProgCode as String
Dim tLookup as Variant
Dim tStudentCharges as Range

tProgCode = oCell.Offset(0,2).Value
Set tStudentCharges = Workbooks(fChargesName).Worksheets("Sheet1"). _
Range(Application.Names("SPTable"))
tLookup = Application.VLookup(tProgCode, tStudentCharges,1,False)

I have checked to see that the tProgCode is pulling the correct field. I
have also checked to make sure the table is being correctly identified with
the Set tStudentCharges line. However, tLookup only evaluates to Error 2042,
even though the tProgCode can be found in the first column of the table. Any
ideas on why this isn't working?
Thanks,

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 923
Default VLookup problem

I think your lookup table assignment is not correct, try.....

Set tStudentCharges =
Workbooks("fChargesName").Worksheets("Sheet1").Ran ge("SPTable")


--
Cheers
Nigel



"LoriL" wrote in message
...
I have three workbooks - one from which I'm running by VBA code, one
workbook
with data and a third workbook with a table of charges. I want to use the
value of a program code field from the database and find that same value
in
the table of charges. For instance, one value from the database program
code
field is ASC. I want to look for that value in the first column of the
table
of charges and return that value, if it's found. Both fields are set to
text
using the format cells function. The table is sorted by ascending program
codes.

In VBA, my code is as follows:

Dim oCell as Object
Dim tProgCode as String
Dim tLookup as Variant
Dim tStudentCharges as Range

tProgCode = oCell.Offset(0,2).Value
Set tStudentCharges = Workbooks(fChargesName).Worksheets("Sheet1"). _
Range(Application.Names("SPTable"))
tLookup = Application.VLookup(tProgCode, tStudentCharges,1,False)

I have checked to see that the tProgCode is pulling the correct field. I
have also checked to make sure the table is being correctly identified
with
the Set tStudentCharges line. However, tLookup only evaluates to Error
2042,
even though the tProgCode can be found in the first column of the table.
Any
ideas on why this isn't working?
Thanks,



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2
Default VLookup problem

Deleting the Application.Names argument gave me an application-defined error
1004...
Any other ideas? Should I just change my program to a With columns(1), c =
..Find... instead of using the VLookup? Seems like it might be less
problematic.

"Nigel" wrote:

I think your lookup table assignment is not correct, try.....

Set tStudentCharges =
Workbooks("fChargesName").Worksheets("Sheet1").Ran ge("SPTable")


--
Cheers
Nigel



"LoriL" wrote in message
...
I have three workbooks - one from which I'm running by VBA code, one
workbook
with data and a third workbook with a table of charges. I want to use the
value of a program code field from the database and find that same value
in
the table of charges. For instance, one value from the database program
code
field is ASC. I want to look for that value in the first column of the
table
of charges and return that value, if it's found. Both fields are set to
text
using the format cells function. The table is sorted by ascending program
codes.

In VBA, my code is as follows:

Dim oCell as Object
Dim tProgCode as String
Dim tLookup as Variant
Dim tStudentCharges as Range

tProgCode = oCell.Offset(0,2).Value
Set tStudentCharges = Workbooks(fChargesName).Worksheets("Sheet1"). _
Range(Application.Names("SPTable"))
tLookup = Application.VLookup(tProgCode, tStudentCharges,1,False)

I have checked to see that the tProgCode is pulling the correct field. I
have also checked to make sure the table is being correctly identified
with
the Set tStudentCharges line. However, tLookup only evaluates to Error
2042,
even though the tProgCode can be found in the first column of the table.
Any
ideas on why this isn't working?
Thanks,




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
Vlookup Problem Bruister via OfficeKB.com Excel Worksheet Functions 0 October 16th 09 01:48 PM
VLOOKUP Problem, Please Help! Susan Excel Discussion (Misc queries) 2 September 4th 08 05:05 PM
VLOOKUP problem Mortir Excel Worksheet Functions 2 April 26th 07 10:48 AM
VLOOKUP Problem brown_toby Excel Worksheet Functions 6 June 30th 06 04:52 PM
VLOOKUP Problem Ian Excel Discussion (Misc queries) 3 April 6th 06 06:47 PM


All times are GMT +1. The time now is 02:23 AM.

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

About Us

"It's about Microsoft Excel"