+ Reply to Thread
Results 1 to 5 of 5

Iferror + If + Index + Match in VBA

Hybrid View

  1. #1
    Registered User
    Join Date
    09-12-2016
    Location
    Montreal, Canada
    MS-Off Ver
    2013
    Posts
    23

    Iferror + If + Index + Match in VBA

    Hi All,

    I need help to translate the two formulas below into VBA.

    Thanks a lot for your help.

    Formula 1:

    =IFERROR(D2/(IF(ISNUMBER(INDEX(Tableau!T:T,MATCH(K2,Tableau!R:R,0))), (INDEX(Tableau!T:T,MATCH(K2,Tableau!R:R,0))),INDEX(Tableau!V:V,MATCH(J2,Tableau!Q:Q,0))))-1,"Not in Catwalk")
    Formula 2 :

    =IFERROR(IF(ISNUMBER(INDEX(Tableau!W:W,MATCH(K2,Tableau!R:R,0))), (INDEX(Tableau!W:W,MATCH(K2,Tableau!R:R,0))),INDEX(Tableau!X:X,MATCH(J2,Tableau!Q:Q,0))),"Not in Catwalk")

  2. #2
    Forum Guru xlnitwit's Avatar
    Join Date
    06-27-2016
    Location
    London
    MS-Off Ver
    Windows: 2010; Mac: 16.13 (O365)
    Posts
    7,085

    Re: Iferror + If + Index + Match in VBA

    Hi,

    What do you mean by "translate to VBA"? How do you intend to use them and why is a formula not a viable option?
    Don
    Please remember to mark your thread 'Solved' when appropriate.

  3. #3
    Registered User
    Join Date
    09-12-2016
    Location
    Montreal, Canada
    MS-Off Ver
    2013
    Posts
    23
    Quote Originally Posted by xlnitwit View Post
    Hi,

    What do you mean by "translate to VBA"? How do you intend to use them and why is a formula not a viable option?
    See above.

  4. #4
    Forum Guru Kaper's Avatar
    Join Date
    12-14-2013
    Location
    Warsaw, Poland
    MS-Off Ver
    most often: Office 365 in Windows environment
    Posts
    8,864

    Re: Iferror + If + Index + Match in VBA

    ...And what shall be done with the result?
    If it is to be stored in a cell where formula would reside, probably easiest approach is to write there formula and then store as value. Note single quotation marks replaced by double:

    Range("A1").formula = "=IFERROR(D2/(IF(ISNUMBER(INDEX(Tableau!T:T,MATCH(K2,Tableau!R:R,0))), (INDEX(Tableau!T:T,MATCH(K2,Tableau!R:R,0))),INDEX(Tableau!V:V,MATCH(J2,Tableau!Q:Q,0))))-1,""Not in Catwalk"")"
    Range("A1").value= Range("A1").value
    if it is to be stored in variable use
    start with something like
    dim result_cell as range
    set result_cell  = sheets("Tableau").Columns("R:R").Find (what:= Range("K2").value, LookIn:=xlValues, lookat:=xlWhole).offset(0,2) 'offset, because T is 2 columns right from R
    if not isnumeric(result_cell) then
      set result_cell  = sheets("Tableau").Columns("Q:Q").Find (what:= Range("J2").value, LookIn:=xlValues, lookat:=xlWhole).offset(0,5) 'offset, because V is 5 columns right from Q
    end if
    ' and here next test probably if result cell is a number or may be if it is not 1 (D2/0 would raise an error too)
    edit: first question is of course the same as above. But I started writing a bit earlier, it just took me few minutes to write the code :-)
    Best Regards,

    Kaper

  5. #5
    Registered User
    Join Date
    09-12-2016
    Location
    Montreal, Canada
    MS-Off Ver
    2013
    Posts
    23
    Quote Originally Posted by Kaper View Post
    ...And what shall be done with the result?
    If it is to be stored in a cell where formula would reside, probably easiest approach is to write there formula and then store as value. Note single quotation marks replaced by double:

    Range("A1").formula = "=IFERROR(D2/(IF(ISNUMBER(INDEX(Tableau!T:T,MATCH(K2,Tableau!R:R,0))), (INDEX(Tableau!T:T,MATCH(K2,Tableau!R:R,0))),INDEX(Tableau!V:V,MATCH(J2,Tableau!Q:Q,0))))-1,""Not in Catwalk"")"
    Range("A1").value= Range("A1").value
    if it is to be stored in variable use
    start with something like
    dim result_cell as range
    set result_cell  = sheets("Tableau").Columns("R:R").Find (what:= Range("K2").value, LookIn:=xlValues, lookat:=xlWhole).offset(0,2) 'offset, because T is 2 columns right from R
    if not isnumeric(result_cell) then
      set result_cell  = sheets("Tableau").Columns("Q:Q").Find (what:= Range("J2").value, LookIn:=xlValues, lookat:=xlWhole).offset(0,5) 'offset, because V is 5 columns right from Q
    end if
    ' and here next test probably if result cell is a number or may be if it is not 1 (D2/0 would raise an error too)
    edit: first question is of course the same as above. But I started writing a bit earlier, it just took me few minutes to write the code :-)

    Thanks a lot. My sheet has hunderds of thousands of rows therefore, vba is a better option rather than writing a formula for each cell.

+ 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. Use of If, Iferror, Match or Index Formulas
    By M. Shahbaz in forum Excel General
    Replies: 1
    Last Post: 01-15-2017, 07:17 AM
  2. Iferror + index/match + vlookup
    By annieflanz in forum Excel Formulas & Functions
    Replies: 1
    Last Post: 09-15-2016, 02:48 PM
  3. [SOLVED] Sum used with index match and iferror
    By tlstevens in forum Excel Formulas & Functions
    Replies: 3
    Last Post: 05-08-2015, 02:43 PM
  4. [SOLVED] Iferror, index & match
    By meh999 in forum Excel Formulas & Functions
    Replies: 12
    Last Post: 07-26-2014, 08:43 AM
  5. Adding IFERROR to INDEX MATCH
    By brad999 in forum Excel Formulas & Functions
    Replies: 2
    Last Post: 12-06-2013, 04:18 AM
  6. Looking for better formula of iferror, index and match
    By DavidRoger in forum Excel Formulas & Functions
    Replies: 3
    Last Post: 09-23-2012, 07:50 AM

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