+ Reply to Thread
Results 1 to 2 of 2

VLOOKUP from another sheet VBA programming

  1. #1
    Guest

    VLOOKUP from another sheet VBA programming

    hi,

    I have 2 sheets in my workbook,

    sheet 1 contains the main analysis of my data

    sheet 2 contains a table which I will reference with VLOOKUP from sheet 1


    I have written the following VBA code for my purpose:
    Worksheets(1).Activate //activate sheet 1
    Range("M2").FormulaR1C1 = "=VLOOKUP(RC[-5], lookuptable'!$A2:$B38, 2,
    false)" //input into cell M2 of sheet 1 this formula.

    when I run my code,
    cell M2 in sheet 1 will give a #NAME? error and when I look at the formula
    in the cell:
    =VLOOKUP(H2,personal.xls!'A2':'B38',2,FALSE)

    notice the extra single quotes around A2 and B38.

    ps: i defined my module in personal.xls to be able to access it from any
    workbook.

    thnks.
    Michael.


  2. #2
    Tom Ogilvy
    Guest

    Re: VLOOKUP from another sheet VBA programming

    You can't mix R1C1 notation and A1 notation in a formula such as you have.

    Range("M2").FormulaR1C1 = "=VLOOKUP(RC[-5], lookuptable!R2C1:R38C2,
    2,false)"

    --
    Regards,
    Tom Ogilvy

    <a> wrote in message news:[email protected]...
    > hi,
    >
    > I have 2 sheets in my workbook,
    >
    > sheet 1 contains the main analysis of my data
    >
    > sheet 2 contains a table which I will reference with VLOOKUP from sheet 1
    >
    >
    > I have written the following VBA code for my purpose:
    > Worksheets(1).Activate //activate sheet 1
    > Range("M2").FormulaR1C1 = "=VLOOKUP(RC[-5], lookuptable'!$A2:$B38, 2,
    > false)" //input into cell M2 of sheet 1 this formula.
    >
    > when I run my code,
    > cell M2 in sheet 1 will give a #NAME? error and when I look at the

    formula
    > in the cell:
    > =VLOOKUP(H2,personal.xls!'A2':'B38',2,FALSE)
    >
    > notice the extra single quotes around A2 and B38.
    >
    > ps: i defined my module in personal.xls to be able to access it from any
    > workbook.
    >
    > thnks.
    > Michael.
    >




+ 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