+ Reply to Thread
Results 1 to 8 of 8

Vlookup with VBA

Hybrid View

  1. #1
    Registered User
    Join Date
    09-07-2007
    Posts
    5

    Vlookup with VBA

    Hi All,

    I'm trying to find out a way to solve this problem:

    I have an external password-protect xls file in which there is the second worksheet that contains a list of elements like the following one:

    Column A Column B
    10-Sep-2007 10am-19am
    11-Sep-2007 10am-19am
    12-Sep-2007 09am-18-am

    I need to locate a specific cell in the Column B depending on the actual day and paste the content into my Excel Sheet.

    I was able to open the external file, but I was only able to retrieve the content of a specified cell.

    This is the code I'm using:
     
    Sub GetDataFromClosedWorkbook()
    Dim wb As Workbook
    Dim myNumberFormat As String
        myNumberFormat = today
        Application.ScreenUpdating = False ' turn off the screen updating
        Set wb = Workbooks.Open("N:\Calendar.xls", True, True)
        ' open the source workbook, read only
        With ThisWorkbook.Worksheets(2)
            ' read data from the source workbook
            Set RNG = wb.Worksheets(2).Range("C13:AM1000")
            .Range("B4").Value = wb.Worksheets(2).VLookup(today(), RNG, 2, True)
            ' trying to retrieve the value
            .Range("A22").Formula = wb.Worksheets(2).Range("D6").Formula
            'this works
        End With
        wb.Close False ' close the source workbook without saving any changes
        Set wb = Nothing ' free memory
        Application.ScreenUpdating = True ' turn on the screen updating
    End Sub
    Anyone can suggest me how to correct that Vlookup function?????

    Any help will be really appreciated!!!

    Thank you,
    Steve
    Last edited by VBA Noob; 09-18-2007 at 10:24 AM.

  2. #2
    Forum Expert royUK's Avatar
    Join Date
    11-18-2003
    Location
    Derbyshire,UK
    MS-Off Ver
    Xp; 2007; 2010
    Posts
    26,200
    I wouldn't use VLOOKUP, but use the .Find method. I'm not sure exactly what you want to do, attach an example workbook.
    Hope that helps.

    RoyUK
    --------
    For Excel Tips & Solutions, free examples and tutorials why not check out my web site

    Free DataBaseForm example

  3. #3
    Registered User
    Join Date
    09-07-2007
    Posts
    5

    Example

    Thank you RoyUK for your reply!

    I'll try to better explain what I'm trying to do with a couple of screenshots:

    Let's say that I want to display in the cell B4 (attachment "file1.jpg") the exact copy of the content of the cells on the B column on the second attachment (file2.jpg - external file) depending on the day.

    So, if today were 17/09/2007 I would like to have in B4 the value 10-7pm

    Possibly not important, but please note that the date's values are in the format d/m/yyyy

    What I'm receiving is just #N/A

    Do you think that .find is the solution?


    Thank you very much!
    Steve
    Attached Images Attached Images

  4. #4
    Forum Expert royUK's Avatar
    Join Date
    11-18-2003
    Location
    Derbyshire,UK
    MS-Off Ver
    Xp; 2007; 2010
    Posts
    26,200
    I can help you better if you attach a workbook example.

  5. #5
    Registered User
    Join Date
    09-07-2007
    Posts
    5

    'Real' Example

    Hi RoyUK!

    You are right, I'm attaching two examples (basically these are the worksheets I'm using, just without most of the data to make them smaller)...

    Basically, the file "shifts.xls" will have to find and read info from calendar.xls using vlookup...

    Calendar.xls is a password protected file, and the pwd is "test"...

    RoyUK, thank you for your help!!!
    Steve

  6. #6
    Registered User
    Join Date
    09-07-2007
    Posts
    5

    Attachments

    Ooops...

    here you have the attachments...

    :-)
    Attached Files Attached Files

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1