+ Reply to Thread
Results 1 to 7 of 7

Lookup Formula in VBA

  1. #1
    Forum Contributor
    Join Date
    07-07-2014
    Location
    Göteborg
    MS-Off Ver
    2010
    Posts
    130

    Lookup Formula in VBA

    In column 15 today there is a following formula which is working as intended (Find the last cell with data..).
    =LOOKUP(2;1/(F3:N3<>"");F3:N3)

    The thing is that I would like to VBA to write this formula instead so I don't have to have the formula, just what is result in.
    This formula is the same formula in every row until the last row. The only difference is that it changes what row the formula is using. Below is how the formula changes when you go down a row.

    =LOOKUP(2;1/(F3:N3<>"");F3:N3)
    =LOOKUP(2;1/(F4:N4<>"");F4:N4)
    =LOOKUP(2;1/(F5:N5<>"");F5:N5)

    I have tried to fix a code by myself which is not working right now because of simple mistake probably.

    Please Login or Register  to view this content.
    Can anyone explain what I do wrong in my code?
    Last edited by gandreso; 12-06-2016 at 11:00 AM.

  2. #2
    Valued Forum Contributor
    Join Date
    12-02-2009
    Location
    Austin, Tx
    MS-Off Ver
    Office 365 64-Bit, 2108, build 14326.21018
    Posts
    3,946

    Re: Lookup Formula in VBA

    Can you post a sample file and explain what "not working" means? IE "No result", "gives wrong value", "crashes Excel", etc.

  3. #3
    Valued Forum Contributor
    Join Date
    12-02-2009
    Location
    Austin, Tx
    MS-Off Ver
    Office 365 64-Bit, 2108, build 14326.21018
    Posts
    3,946

    Re: Lookup Formula in VBA

    Deleted Msg

  4. #4
    Forum Contributor
    Join Date
    07-07-2014
    Location
    Göteborg
    MS-Off Ver
    2010
    Posts
    130

    Re: Lookup Formula in VBA

    Here is a examplefile attached with the code. When I say it doesn't work, I mean that VBA says "Type Mismatch", a run time error 13.
    Attached Files Attached Files

  5. #5
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    44,088

    Re: Lookup Formula in VBA

    Maybe stick with using the formula but in VBA, no loop required:

    Please Login or Register  to view this content.
    Or you could probably use Evaluate

    Please Login or Register  to view this content.
    Trevor Shuttleworth - Retired Excel/VBA Consultant

    I dream of a better world where chickens can cross the road without having their motives questioned

    'Being unapologetic means never having to say you're sorry' John Cooper Clarke


  6. #6
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    44,088

    Re: Lookup Formula in VBA

    Sorry, commas need to be replaced by semi-colons in formula in first reply

  7. #7
    Forum Contributor
    Join Date
    07-07-2014
    Location
    Göteborg
    MS-Off Ver
    2010
    Posts
    130

    Re: Lookup Formula in VBA

    Thanks for your help. It does exactly what I wants.

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. Multi criteria lookup with the ''=lookup' formula
    By Ronnet2 in forum Excel Formulas & Functions
    Replies: 15
    Last Post: 09-17-2015, 07:12 AM
  2. Replies: 4
    Last Post: 05-19-2015, 08:42 PM
  3. [SOLVED] Lookup formula to find lowest value with variable lookup criteria
    By brharrii in forum Excel Formulas & Functions
    Replies: 6
    Last Post: 01-27-2015, 03:00 AM
  4. [SOLVED] Can lookup formula ignore blank cells until the lookup value has been entered?
    By Ju1cy in forum Excel Formulas & Functions
    Replies: 9
    Last Post: 06-13-2014, 01:32 PM
  5. Create a lookup formula with an If or Lookup function
    By afountas21 in forum Excel General
    Replies: 2
    Last Post: 09-05-2012, 06:53 PM
  6. Replies: 5
    Last Post: 02-24-2011, 11:26 AM
  7. Replies: 3
    Last Post: 10-10-2005, 01:05 PM

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