Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 493
Default using VLOOKUP from MS Access

I'm openning an excel workbook with many spreadsheets from MS Access by using
the following code:

Dim xlapp As New Excel.Application
Dim xlbook As New Excel.Workbook

Set xlbook = xlapp.Workbooks.Open(strFileName, True)

How could I use VLOOKUP to find a needed number from Sheet1 in this workbook?

Thanks


  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 983
Default using VLOOKUP from MS Access

In excel you can use

Application.vlookup(What, Where, 1, False)

So I would think that you could try

xlbook.vlookup.(What, Where, 1, False)

Let me know if that works...

"Alex" wrote:

I'm openning an excel workbook with many spreadsheets from MS Access by using
the following code:

Dim xlapp As New Excel.Application
Dim xlbook As New Excel.Workbook

Set xlbook = xlapp.Workbooks.Open(strFileName, True)

How could I use VLOOKUP to find a needed number from Sheet1 in this workbook?

Thanks


  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,758
Default using VLOOKUP from MS Access

This worked in MSWord with a reference to MSExcel.

Option Explicit
Sub testme()

Dim xlApp As Excel.Application
Dim xlBook As New Excel.Workbook
Dim strFileName As String
Dim res As Variant
Dim myRng As Excel.Range
Dim myVal As Variant

strFileName = "C:\my documents\excel\book1.xls"

myVal = "asdf3"

Set xlApp = New Excel.Application
xlApp.Visible = True 'nice for testing

Set xlBook = xlApp.Workbooks.Open(strFileName, True)
Set myRng = xlBook.Worksheets("Sheet1").Range("a1:E99")

res = xlApp.VLookup(myVal, myRng, 2, False)

If IsError(res) Then
MsgBox "No match"
Else
MsgBox res
End If

xlBook.Close savechanges:=False
xlApp.Quit

Set myRng = Nothing
Set xlBook = Nothing
Set xlApp = Nothing

End Sub

Alex wrote:

I'm openning an excel workbook with many spreadsheets from MS Access by using
the following code:

Dim xlapp As New Excel.Application
Dim xlbook As New Excel.Workbook

Set xlbook = xlapp.Workbooks.Open(strFileName, True)

How could I use VLOOKUP to find a needed number from Sheet1 in this workbook?

Thanks


--

Dave Peterson
  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 493
Default using VLOOKUP from MS Access

Thanks a lot, Jim.

I'm trying this after the workbook's openning but may be something wrong
with how I'm using the path to the file or a range. So, it's not working.

With xlbook

curCost = .WorksheetFunction.VLookup(strRecipeNum,
"'S:\Operations\Products\Recipes\[MRP-Recipes.xls]'!A1:C400", 12, False)

End With

"Jim Thomlinson" wrote:

In excel you can use

Application.vlookup(What, Where, 1, False)

So I would think that you could try

xlbook.vlookup.(What, Where, 1, False)

Let me know if that works...

"Alex" wrote:

I'm openning an excel workbook with many spreadsheets from MS Access by using
the following code:

Dim xlapp As New Excel.Application
Dim xlbook As New Excel.Workbook

Set xlbook = xlapp.Workbooks.Open(strFileName, True)

How could I use VLOOKUP to find a needed number from Sheet1 in this workbook?

Thanks


  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 493
Default using VLOOKUP from MS Access

Thanks a lot, Dave.

The code goes without any error messages. But, just my vlookup function
cannot return any value. It returns error 2042.

It looks like i'm doing the same, but .....

Set xlbook = xlApp.Workbooks.Open(strFileName, True)

Set myRng = xlbook.Worksheets("Legend").Range("C3:L500")

'With xlbook
' .Worksheets("Legend").Range("C3:L500").Name = "d"
'End With ' I've checked, just in case, whether the range can be set up there.

varCost = xlApp.VLookup(strVal, myRng, 12, False)

I think, there is some simple mistake, but I cannot see it.

"Dave Peterson" wrote:

This worked in MSWord with a reference to MSExcel.

Option Explicit
Sub testme()

Dim xlApp As Excel.Application
Dim xlBook As New Excel.Workbook
Dim strFileName As String
Dim res As Variant
Dim myRng As Excel.Range
Dim myVal As Variant

strFileName = "C:\my documents\excel\book1.xls"

myVal = "asdf3"

Set xlApp = New Excel.Application
xlApp.Visible = True 'nice for testing

Set xlBook = xlApp.Workbooks.Open(strFileName, True)
Set myRng = xlBook.Worksheets("Sheet1").Range("a1:E99")

res = xlApp.VLookup(myVal, myRng, 2, False)

If IsError(res) Then
MsgBox "No match"
Else
MsgBox res
End If

xlBook.Close savechanges:=False
xlApp.Quit

Set myRng = Nothing
Set xlBook = Nothing
Set xlApp = Nothing

End Sub

Alex wrote:

I'm openning an excel workbook with many spreadsheets from MS Access by using
the following code:

Dim xlapp As New Excel.Application
Dim xlbook As New Excel.Workbook

Set xlbook = xlapp.Workbooks.Open(strFileName, True)

How could I use VLOOKUP to find a needed number from Sheet1 in this workbook?

Thanks


--

Dave Peterson



  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 493
Default using VLOOKUP from MS Access

I found a mistake.

If I'm using the range such as C3:L500, I should use 10 for column (not 12).

Thanks everybody.



"Alex" wrote:

Thanks a lot, Dave.

The code goes without any error messages. But, just my vlookup function
cannot return any value. It returns error 2042.

It looks like i'm doing the same, but .....

Set xlbook = xlApp.Workbooks.Open(strFileName, True)

Set myRng = xlbook.Worksheets("Legend").Range("C3:L500")

'With xlbook
' .Worksheets("Legend").Range("C3:L500").Name = "d"
'End With ' I've checked, just in case, whether the range can be set up there.

varCost = xlApp.VLookup(strVal, myRng, 12, False)

I think, there is some simple mistake, but I cannot see it.

"Dave Peterson" wrote:

This worked in MSWord with a reference to MSExcel.

Option Explicit
Sub testme()

Dim xlApp As Excel.Application
Dim xlBook As New Excel.Workbook
Dim strFileName As String
Dim res As Variant
Dim myRng As Excel.Range
Dim myVal As Variant

strFileName = "C:\my documents\excel\book1.xls"

myVal = "asdf3"

Set xlApp = New Excel.Application
xlApp.Visible = True 'nice for testing

Set xlBook = xlApp.Workbooks.Open(strFileName, True)
Set myRng = xlBook.Worksheets("Sheet1").Range("a1:E99")

res = xlApp.VLookup(myVal, myRng, 2, False)

If IsError(res) Then
MsgBox "No match"
Else
MsgBox res
End If

xlBook.Close savechanges:=False
xlApp.Quit

Set myRng = Nothing
Set xlBook = Nothing
Set xlApp = Nothing

End Sub

Alex wrote:

I'm openning an excel workbook with many spreadsheets from MS Access by using
the following code:

Dim xlapp As New Excel.Application
Dim xlbook As New Excel.Workbook

Set xlbook = xlapp.Workbooks.Open(strFileName, True)

How could I use VLOOKUP to find a needed number from Sheet1 in this workbook?

Thanks


--

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 from Access MitzDriver Excel Discussion (Misc queries) 3 September 7th 09 12:34 AM
Using VLOOKUP to look up info from Access Michelle Excel Worksheet Functions 0 June 7th 09 04:53 PM
vlookup from Access db PsyberFox Links and Linking in Excel 3 November 6th 08 03:14 PM
VLOOKUP from Access Tables Mraggie Excel Worksheet Functions 0 August 9th 06 08:36 PM
Vlookup to Access Dbase chris huber Excel Programming 2 December 24th 03 04:03 AM


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