+ Reply to Thread
Results 1 to 4 of 4

VLOOKUP form a workbook to another one

Hybrid View

  1. #1
    Registered User
    Join Date
    10-29-2012
    Location
    México
    MS-Off Ver
    Excel 2010
    Posts
    8

    VLOOKUP form a workbook to another one

    Hello
    I have this problem. I am trying to make several files that grab information from another workbook with loads of rows with lots of data. So I'm trying to use the vlookup function to grab that information when it is required. I am not really good at this and all I know I've learned it myself so sorry if there are many many mistakes. Here is what I've written
    Sub Buscar()
    Dim anexo As Variant
    Dim cliente As String
    Dim maturity As Date
    Dim contacto As String
    Dim contactod As String
    Dim responsable As String
    Dim texto As String
    Dim i As Integer
    Dim fecha As String
    Dim evento As String
    Dim referencia As String
    'buscar info general
    texto = InputBox("Introducir número de anexo")
    Range("C5") = texto
    anexo = texto
    Workbooks.Open Filename:="C:\Users\Ana Méndez\Desktop\Caralogo base.xlsx"
        Sheets("Anexos").Activate
        cliente = WorksheetFunction.VLookup(anexo, Range("A1", "F1000"), 2, False)
        maturity = WorksheetFunction.VLookup(anexo, Range("A1", "F1000"), 3, False)
        contacto = WorksheetFunction.VLookup(anexo, Range("A1", "F1000"), 4, False)
        contactod = WorksheetFunction.VLookup(anexo, Range("A1", "F1000"), 5, False)
        responsable = WorksheetFunction.VLookup(anexo, Range("A1", "F1000"), 6, False)
    Workbooks.Open Filename:="C:\Users\Ana Méndez\Desktop\Formato 1.xlsm"
        Sheets("Formato").Activate
        Range("c7") = cliente
        Range("c8") = maturity
        Range("c9") = contacto
        Range("c10") = contactod
        Range("c11") = responsable
    Thank you for all of your help!

  2. #2
    Registered User
    Join Date
    10-29-2012
    Location
    México
    MS-Off Ver
    Excel 2010
    Posts
    8

    Re: VLOOKUP form a workbook to another one

    The problem is in the WorksheetFunction.VLookup part. I get a mistake saying that it is the mistake 1004 and that Vlookup cannot be obtained from worksheetfunction

  3. #3
    Administrator FDibbins's Avatar
    Join Date
    12-29-2011
    Location
    Duncansville, PA USA
    MS-Off Ver
    Excel 7/10/13/16/365 (PC ver 2310)
    Posts
    53,048

    Re: VLOOKUP form a workbook to another one

    why do you need to do this through a macro? would a simple vlookup() formula not do what you need?
    1. Use code tags for VBA. [code] Your Code [/code] (or use the # button)
    2. If your question is resolved, mark it SOLVED using the thread tools
    3. Click on the star if you think someone helped you

    Regards
    Ford

  4. #4
    Registered User
    Join Date
    10-29-2012
    Location
    México
    MS-Off Ver
    Excel 2010
    Posts
    8

    Re: VLOOKUP form a workbook to another one

    Thank you!
    Well, in that part it could be changed just as you say, but I was trying to make that part work because I was using the same function afterwards, searching different lines of every category,but now since you are saying it can be changed I think that it could be replaced by just copy-pasting the information like this
    For i = 1 To 4000
        If Cells(i, 1) = texto Then fecha = Cells(i, 2).Value And evento = Cells(i, 3).Value And referencia = Cells(i, 4).Value
            NextRow = WorksheetFunction.CountA(Columns("A:A")) + 1
            Cells(NextRow + 14, 1).Value = "1"
            Cells(NextRow + 14, 2).Value = fecha
            Cells(NextRow + 14, 3).Value = evento
            Cells(NextRow + 14, 4).Value = referencia
    Next i
    I'll try to do that properly then!

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Tags for this Thread

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