+ Reply to Thread
Results 1 to 6 of 6

Currentregion and/or range naming

  1. #1
    Registered User
    Join Date
    03-15-2007
    Posts
    50

    Currentregion and/or range naming

    I want to refer to a range on a worksheet that will be dynamic (it will be added to over time) I defined a variable (rng as Range) and want to refer that to the data. How do I set the rng variable to be all of that data to be used in a vlookup?

    ex. If I select A1 and use the Currentregion.select, can I then name that currentregion and then use that name in the vlookup? How would I refer to the name of the range?

    thanks

  2. #2
    Forum Contributor VBA Noob's Avatar
    Join Date
    04-25-2006
    Location
    London, England
    MS-Off Ver
    xl03 & xl 07(Jan 09)
    Posts
    11,988
    Hi,

    Would a dynamic range help

    http://www.contextures.com/xlNames01.html#Dynamic

    VBA Noob
    _________________________________________


    Credo Elvem ipsum etian vivere
    _________________________________________
    A message for cross posters

    Please remember to wrap code.

    Forum Rules

    Please add to your signature if you found this link helpful. Excel links !!!

  3. #3
    Registered User
    Join Date
    03-15-2007
    Posts
    50
    Yes, that works. Now how do I refer to that in the vlookup? as a test, I set a static range and called it "events". From my main sheet, I want to do a vlookup on that data and I plugged in the following:

    ActiveCell.Formula = "=if(iserror(vlookup(F4,(events),8,false)),"",vlookup(F4,(events),8,false))"

    I get a runtime 1004 application-defined or object-defined error

    Do I have to activate the sheet where the "events" range is resident before running that line?

  4. #4
    Forum Contributor VBA Noob's Avatar
    Join Date
    04-25-2006
    Location
    London, England
    MS-Off Ver
    xl03 & xl 07(Jan 09)
    Posts
    11,988
    Please wrap code next time

    You could try

    Please Login or Register  to view this content.
    VBA Noob
    Last edited by VBA Noob; 03-18-2007 at 07:44 PM.

  5. #5
    Registered User
    Join Date
    03-15-2007
    Posts
    50
    Sorry about that. I stepped through it and it ran without an error.

    thanks

  6. #6
    Forum Contributor VBA Noob's Avatar
    Join Date
    04-25-2006
    Location
    London, England
    MS-Off Ver
    xl03 & xl 07(Jan 09)
    Posts
    11,988
    Glad you sorted your problem

    VBA Noob

+ 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