+ Reply to Thread
Results 1 to 9 of 9

Thread: Macros- v look up populating to the last row PLEASE HELP

  1. #1
    Registered User
    Join Date
    02-09-2012
    Location
    USA
    MS-Off Ver
    Excel 2003
    Posts
    5

    Angry Macros- v look up populating to the last row PLEASE HELP

    Ok, I am by no means an excell whizz, but I do have some experience. I have a long macros calculating costs and when to dispatch work orders. I run this each week. The number of rows changes from week to week. I am looking to put a v look up in the macros to automatically stop at the last populated row.

    I have:

    ActiveCell.FormulaR1C1 = "=VLOOKUP(RC[-15],Sheet2!C[-27]:C[-26],2,FALSE)"
    Selection.AutoFill Destination:=Range("AB2:AB272")
    Range("AB2:AB272").Select

    I want to replace AB272 with something that will automatically populate the number of rows in sheet 1. I have tried many things and had little luck getting it to work.

    Please help!!

  2. #2
    Forum Guru
    Join Date
    01-15-2007
    Location
    Brisbane, Australia
    MS-Off Ver
    2007
    Posts
    5,359

    Re: Macros- v look up populating to the last row PLEASE HELP

    Hi

    Find a column that will have an entry in the last row (say column A) then do something like

    range("AB2").autofill destination:=range("AB2:AB" & cells(rows.count,"A").end(xlup).row)
    rylo

  3. #3
    Registered User
    Join Date
    02-09-2012
    Location
    USA
    MS-Off Ver
    Excel 2003
    Posts
    5

    Re: Macros- v look up populating to the last row PLEASE HELP

    thanks,

    Maybe I am an idiot, Still not working. I have:

    ActiveCell.FormulaR1C1 = "=VLOOKUP(RC[-15],Sheet2!C[-27]:C[-26],2,FALSE)"
    Selection.Range("AB2").AutoFill Destination:=Range("AB2:AB" & Cells(Rows.Count, "A").End(xlUp).Row)

  4. #4
    Forum Guru
    Join Date
    01-15-2007
    Location
    Brisbane, Australia
    MS-Off Ver
    2007
    Posts
    5,359

    Re: Macros- v look up populating to the last row PLEASE HELP

    Hi

    Put up an example workbook.

    rylo

  5. #5
    Registered User
    Join Date
    02-09-2012
    Location
    USA
    MS-Off Ver
    Excel 2003
    Posts
    5

    Re: Macros- v look up populating to the last row PLEASE HELP


  6. #6
    Forum Guru
    Join Date
    01-15-2007
    Location
    Brisbane, Australia
    MS-Off Ver
    2007
    Posts
    5,359

    Re: Macros- v look up populating to the last row PLEASE HELP

    Hi
    Range("AB2").autofill...
    not
    selection.range("AB2").autofill....
    Big assumption is that you are actually in AB2 when you put in the vlookup formula of course.

    rylo

  7. #7
    Registered User
    Join Date
    02-09-2012
    Location
    USA
    MS-Off Ver
    Excel 2003
    Posts
    5

    Re: Macros- v look up populating to the last row PLEASE HELP

    this gives a run time error stating that "autofill method of Range class failed"

    Select ("AB2")
    ActiveCell.FormulaR1C1 = "=VLOOKUP(RC[-15],Sheet2!C[-27]:C[-26],2,FALSE)"
    Range("AB2").AutoFill Destination:=Range("AB2:AB" & Cells(Rows.Count, "AB").End(xlUp).Row)

  8. #8
    Forum Guru
    Join Date
    01-15-2007
    Location
    Brisbane, Australia
    MS-Off Ver
    2007
    Posts
    5,359

    Re: Macros- v look up populating to the last row PLEASE HELP

    Hi

    You are trying to use the column with the formula as the basis for extracting the last row. I opened your example file test.xls from post #5 and ran

      Range("AB2").Select
      ActiveCell.FormulaR1C1 = "=VLOOKUP(RC[-15],Sheet2!C[-27]:C[-26],2,FALSE)"
      Range("AB2").AutoFill Destination:=Range("AB2:AB" & Cells(Rows.Count, "A").End(xlUp).Row)
    and go no errors.

    rylo

  9. #9
    Registered User
    Join Date
    02-09-2012
    Location
    USA
    MS-Off Ver
    Excel 2003
    Posts
    5

    Re: Macros- v look up populating to the last row PLEASE HELP

    thanks all is good. thanks so much

+ 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.2.0