#1   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 48
Default VLOOKUP in VB

Hi,

I have a vlookup in VB and I'm pretty sure it's working, except it
returns a #N/A as the result. I'm pretty sure this is because of the
"format" I am using, but I'm not sure how to change it. I'm looking up
a date from one column, finding it in another and returning the second
column (a percent with up to 5 decimals). What should I be using to
get this to work:

Sub GetRates()

Dim Row As Integer
Dim Dates As Date
Dim Libor As Date

Row = 3

Dates = Sheets("Libor").Cells(Row, 2).Value
Libor = Application.VLookup(Worksheets("Libor").Cells(Row, 2).Value,
Worksheets("BB").Range("B:C"), 2, False)

Cells(Row, 3).Value = Libor


End Sub

I have Row as a variable because I will be adding to it.

Thanks,
Brett

  #2   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 35,218
Default VLOOKUP in VB

I wouldn't use variables that look like VBA properties (or any reserved word).

Option Explicit
Sub GetRates()

Dim myRow As Long
Dim Dates As Date
Dim Libor As Variant 'could return an error

myRow = 3

Dates = Sheets("Libor").Cells(Row, 2).Value
Libor = Application.VLookup(Dates, Worksheets("BB").Range("B:C"), 2, False)
'if that doesn't help, try:
'Libor = Application.VLookup(clng(Dates), _
' Worksheets("BB").Range("B:C"), 2, False)

if iserror(libor) then
libor = "missing"
end if

Cells(Row, 3).Value = Libor

End Sub

====
Sometimes, VBA can have trouble with dates. If you use clng(dates), it might
work.

wrote:

Hi,

I have a vlookup in VB and I'm pretty sure it's working, except it
returns a #N/A as the result. I'm pretty sure this is because of the
"format" I am using, but I'm not sure how to change it. I'm looking up
a date from one column, finding it in another and returning the second
column (a percent with up to 5 decimals). What should I be using to
get this to work:

Sub GetRates()

Dim Row As Integer
Dim Dates As Date
Dim Libor As Date

Row = 3

Dates = Sheets("Libor").Cells(Row, 2).Value
Libor = Application.VLookup(Worksheets("Libor").Cells(Row, 2).Value,
Worksheets("BB").Range("B:C"), 2, False)

Cells(Row, 3).Value = Libor

End Sub

I have Row as a variable because I will be adding to it.

Thanks,
Brett


--

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
VLookup a Vlookup adamb2000 Excel Worksheet Functions 4 June 28th 06 10:54 PM
VLOOKUP Problem Ian Excel Discussion (Misc queries) 3 April 6th 06 06:47 PM
VLOOKUP Limitations chris_manning Excel Worksheet Functions 2 August 9th 05 06:23 PM
Have Vlookup return a Value of 0 instead of #N/A Mr Mike Excel Worksheet Functions 4 May 25th 05 04:51 PM
vlookup data hidden within worksheet Excel Worksheet Functions 0 January 26th 05 12:09 PM


All times are GMT +1. The time now is 02:06 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"