+ Reply to Thread
Results 1 to 13 of 13

Index function in vba not returning result

  1. #1
    Registered User
    Join Date
    05-03-2014
    Location
    france
    MS-Off Ver
    Excel 2010
    Posts
    6

    Index function in vba not returning result

    Hi all,

    I want an Index / Match function to return a result from another workbook but no matter the way i try my variable "orderamount" still returns nothing:


    Please Login or Register  to view this content.
    I am using variables in the match functions, one is as string and the other is as date, could that be the problem?

    Thanks in advance for your help.

  2. #2
    Forum Expert
    Join Date
    12-14-2012
    Location
    London England
    MS-Off Ver
    MS 365 Office Suite.
    Posts
    8,448

    Re: Index function in vba not returning result

    I have tested something similar and see no issues.

    A =Application.WorksheetFunction.Match(papername, Workbooks("Journaux_2015.xls").Sheets("Feuil1").Columns(1), 0)
    B = Application.WorksheetFunction.Match(paperdate, Workbooks("Journaux_2015.xls").Sheets("Feuil1").Rows(r), 0))

    Do you get the correct results for both A and B?

    you have entered Columns(1), I think you should be using Columns("A:A")

    you have entered Rows(r), I think you should be using Columns(r & ":" & r)

    You have used several range names do they all exist
    My General Rules if you want my help. Not aimed at any person in particular:

    1. Please Make Requests not demands, none of us get paid here.

    2. Check back on your post regularly. I will not return to a post after 4 days.
    If it is not important to you then it definitely is not important to me.

  3. #3
    Forum Expert
    Join Date
    12-14-2012
    Location
    London England
    MS-Off Ver
    MS 365 Office Suite.
    Posts
    8,448

    Re: Index function in vba not returning result

    I have tested something similar and see no issues.

    A =Application.WorksheetFunction.Match(papername, Workbooks("Journaux_2015.xls").Sheets("Feuil1").Columns(1), 0)
    B = Application.WorksheetFunction.Match(paperdate, Workbooks("Journaux_2015.xls").Sheets("Feuil1").Rows(r), 0))

    Do you get the correct results for both A and B?

    you have entered Columns(1), I think you should be using Columns("A:A")

    you have entered Rows(r), I think you should be using Columns(r & ":" & r)

    You have used several range names do they all exist


    You use
    Please Login or Register  to view this content.
    Does papername exist as a public variable? You may have declared papername as a variable in another macro but you cannot use it in another macro unless it is declared as a public variable.

    You use

    Please Login or Register  to view this content.
    Did you declare sourcerange as a named range in this module or in excel.

    If in another module it should be declared as a public variable. If in excel you should be using something like this:-

    Please Login or Register  to view this content.

  4. #4
    Registered User
    Join Date
    05-03-2014
    Location
    france
    MS-Off Ver
    Excel 2010
    Posts
    6

    Re: Index function in vba not returning result

    Quote Originally Posted by mehmetcik View Post
    I have tested something similar and see no issues.

    A =Application.WorksheetFunction.Match(papername, Workbooks("Journaux_2015.xls").Sheets("Feuil1").Columns(1), 0)
    B = Application.WorksheetFunction.Match(paperdate, Workbooks("Journaux_2015.xls").Sheets("Feuil1").Rows(r), 0))

    Do you get the correct results for both A and B?

    you have entered Columns(1), I think you should be using Columns("A:A")

    you have entered Rows(r), I think you should be using Columns(r & ":" & r)

    You have used several range names do they all exist

    Hi mehmetcik and thanks for your post,

    i tried to run each match function alone but I get the message: "unable to get the match property of the worksheet function class" :

    Please Login or Register  to view this content.

  5. #5
    Forum Guru
    Join Date
    04-13-2005
    Location
    North America
    MS-Off Ver
    2002/XP and 2007
    Posts
    15,826

    Re: Index function in vba not returning result

    Do you know which Match function is failing? If you step through the code (http://www.cpearson.com/Excel/DebuggingVBA.aspx ), which line causes the error?

    Usually this error is because the exact text string (3rd argument to the Match function =0) "Le Matin" is not found in .Columns("A:A") or the exact date value "01/01/2015" is not found in row r. That would be my first guess. This will mean looking through those ranges and at those values and determining if they are there or not. Look for leading/trailing spaces or other non-printing characters in your text strings, and make sure the date search is not missing something because of date/time combinations.

    As a debugging step, you might try pulling values from within the search range. For example,
    Please Login or Register  to view this content.
    so that you know your search values are taken from the database, and should be found. That will give you the opportunity to compare what these variables contain when something known to be in the database is there, and what is there when you enter the constant values that you currently have.
    Quote Originally Posted by shg
    Mathematics is the native language of the natural world. Just trying to become literate.

  6. #6
    Registered User
    Join Date
    05-03-2014
    Location
    france
    MS-Off Ver
    Excel 2010
    Posts
    6

    Re: Index function in vba not returning result

    Quote Originally Posted by MrShorty View Post
    Do you know which Match function is failing? If you step through the code (http://www.cpearson.com/Excel/DebuggingVBA.aspx ), which line causes the error?

    Usually this error is because the exact text string (3rd argument to the Match function =0) "Le Matin" is not found in .Columns("A:A") or the exact date value "01/01/2015" is not found in row r. That would be my first guess. This will mean looking through those ranges and at those values and determining if they are there or not. Look for leading/trailing spaces or other non-printing characters in your text strings, and make sure the date search is not missing something because of date/time combinations.

    As a debugging step, you might try pulling values from within the search range. For example,
    Please Login or Register  to view this content.
    so that you know your search values are taken from the database, and should be found. That will give you the opportunity to compare what these variables contain when something known to be in the database is there, and what is there when you enter the constant values that you currently have.
    when running:

    Please Login or Register  to view this content.
    I get "subscript out of range" !??

  7. #7
    Registered User
    Join Date
    05-03-2014
    Location
    france
    MS-Off Ver
    Excel 2010
    Posts
    6

    Re: Index function in vba not returning result

    Ok i sorted out the match problem using activesheet method but the problem is is my range variable: sourcerange

    the worksheet function does not support this property apparently, any idea?

  8. #8
    Forum Guru
    Join Date
    04-13-2005
    Location
    North America
    MS-Off Ver
    2002/XP and 2007
    Posts
    15,826

    Re: Index function in vba not returning result

    Don't simply copy my typos. I appear to have misread your sheet name. Looking more closely, it looks like it is Feuil1. Subscript out of range means that one of those "workbook" and/or "sheet" and/or "Range" designations is misspelled or not present, and it looks like I misspelled/misread the sheet name.

  9. #9
    Registered User
    Join Date
    05-03-2014
    Location
    france
    MS-Off Ver
    Excel 2010
    Posts
    6

    Re: Index function in vba not returning result

    I did not copy/paste your tread, it is really this range variable that i do not set properly i guess:

    Please Login or Register  to view this content.

  10. #10
    Forum Guru
    Join Date
    04-13-2005
    Location
    North America
    MS-Off Ver
    2002/XP and 2007
    Posts
    15,826

    Re: Index function in vba not returning result

    I did not see this line of code in the previously posted code. The main thing I note in this statement is that the range() method is not qualified, so it will refer to whatever happens to be the currently active sheet. If you qualified your range reference (something like Set sourcerange=workbooks("desired workbook").sheets("desired sheet").range("desired range"), then it should work just fine.

  11. #11
    Forum Expert
    Join Date
    12-14-2012
    Location
    London England
    MS-Off Ver
    MS 365 Office Suite.
    Posts
    8,448

    Re: Index function in vba not returning result

    Look at my previous post. Post #3

    Please Login or Register  to view this content.

  12. #12
    Forum Guru
    Join Date
    04-13-2005
    Location
    North America
    MS-Off Ver
    2002/XP and 2007
    Posts
    15,826

    Re: Index function in vba not returning result

    Now I see, "sourcerange" is a named range in the worksheet, not an object/range variable in VBA.

  13. #13
    Registered User
    Join Date
    05-03-2014
    Location
    france
    MS-Off Ver
    Excel 2010
    Posts
    6

    Re: Index function in vba not returning result

    Hi there, sorry for the late post but i worked it out:

    Please Login or Register  to view this content.
    it was the match function and the date that blocked it all so i used application.match (iso worksheetfunction) and clng(date) to get the date value so it works with every date format

    Thanks to you all for your help!
    Last edited by nikedelik23; 05-01-2015 at 10:52 AM.

+ 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. Index/Match returning 2nd/3rd/nth result in each proceeding column
    By tbar05 in forum Excel Formulas & Functions
    Replies: 3
    Last Post: 04-22-2015, 01:00 AM
  2. [SOLVED] Index match not returning the desired result - help appreciated
    By sipa in forum Excel Formulas & Functions
    Replies: 3
    Last Post: 12-13-2014, 10:41 AM
  3. IF Function Not Returning Logical Result
    By es247 in forum Excel General
    Replies: 13
    Last Post: 06-16-2012, 08:55 PM
  4. Index/Match Returning N/A Result
    By Killer17 in forum Excel General
    Replies: 1
    Last Post: 01-09-2009, 11:15 PM
  5. Index formula returning incorrect result
    By Nadir Soofi in forum Excel Formulas & Functions
    Replies: 1
    Last Post: 06-18-2008, 02:08 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