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

I am using VBA code to print reports from an SQL database using Excel as the
front end. I am trying to use VLOOKUP to find data from a list in one
spreadsheet and include it in an Excel spreadsheet. Here is the code:

If
Application.WorksheetFunction.IsNA(Application.Wor ksheetFunction.VLookup(cnn,
Sheets("Custname").Range("CN"), 4, False)) = False Then
cname = Application.WorksheetFunction.VLookup(cnn, Sheets
"Custname").Range("CN"), 4, False)
Else
cname = "--"
End If

If the data cannot be found, I want to enter dashes in the variable
'cname'l, but if data is found, I want to enter that data in the variable.

The code runs fine as long as the lookup fines data, but if it doesn't the
program halts. What am I doing wrong, and if this doesn't work, what will?

Thanks.



--
Greg
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 61
Default Using VLOOKUP in VBA

Greogrory

Adjust this code its something I have used in the past.

Result = Application.VLookup(Find_CMR, GMB_Table, C + 1, 0)
If IsError(Result) Then
.Cells(5 + i + step, 12 + C) = "--"
End If






"Gregory Howard" wrote in message
...
I am using VBA code to print reports from an SQL database using Excel as
the
front end. I am trying to use VLOOKUP to find data from a list in one
spreadsheet and include it in an Excel spreadsheet. Here is the code:

If
Application.WorksheetFunction.IsNA(Application.Wor ksheetFunction.VLookup(cnn,
Sheets("Custname").Range("CN"), 4, False)) = False Then
cname = Application.WorksheetFunction.VLookup(cnn, Sheets
"Custname").Range("CN"), 4, False)
Else
cname = "--"
End If

If the data cannot be found, I want to enter dashes in the variable
'cname'l, but if data is found, I want to enter that data in the variable.

The code runs fine as long as the lookup fines data, but if it doesn't the
program halts. What am I doing wrong, and if this doesn't work, what
will?

Thanks.



--
Greg



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
If (Vlookup 0) working, but what if Vlookup cell does not exist Steve Excel Worksheet Functions 18 November 18th 09 07:33 PM
VLookUp - Does the VLookUp return the exact information? Cpviv Excel Worksheet Functions 2 October 28th 08 09:57 AM
Vlookup in vlookup - taking the result as array name SupperDuck Excel Worksheet Functions 2 June 2nd 07 11:05 AM
Combine VLOOKUP and IF function so #NA isn't returned as a value from VLOOKUP buffgirl71 Excel Discussion (Misc queries) 12 November 14th 06 11:36 PM
Vlookup info being used without vlookup table attached? Excel Worksheet Functions 0 January 25th 05 10:43 AM


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

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"