+ Reply to Thread
Results 1 to 14 of 14

Compile Error. Sub of Function not Defined.

  1. #1
    Registered User
    Join Date
    07-14-2009
    Location
    London
    MS-Off Ver
    Excel 2003
    Posts
    32

    Compile Error. Sub of Function not Defined.

    Hi, Im really new to VBA Macro and i would appreciate all the help I can get from anyone.
    I have a range of amounts in Sheet 1 from F7:Q13 and im using the find method to search for the active and non active values in the cell. Which means that if there's a value in the cell it will transfer the value in Sheet 2, if nothing is found in the cell the cells in Sheet 2 will return as nothing or null.

    I think the problem lies on the FindWhat variable. Im getting a compiled error which im not sure what is it.

    I've attached the spreadsheet so you get a better idea of the problem that i encountered. Thanks soo much in advance!


    Please Login or Register  to view this content.
    Attached Files Attached Files

  2. #2
    Forum Expert
    Join Date
    01-15-2007
    Location
    Brisbane, Australia
    MS-Off Ver
    2007
    Posts
    6,591

    Re: Compile Error. Sub of Function not Defined.

    Hi

    You don't have any code for the function FindAll in this workbook. What is the code for this function?

    rylo

  3. #3
    Valued Forum Contributor
    Join Date
    05-14-2009
    Location
    gold coast
    MS-Off Ver
    Excel 2007
    Posts
    843

    Re: Compile Error. Sub of Function not Defined.

    Try http://www.cpearson.com/excel/RangeFind.htm It has all the function examples for what you are doing.

  4. #4
    Registered User
    Join Date
    07-14-2009
    Location
    London
    MS-Off Ver
    Excel 2003
    Posts
    32

    Re: Compile Error. Sub of Function not Defined.

    Thanks for the replies.

    I've read the link that you attached but im still confuse as to how i can find the values in the cells. Im trying to use the Dim Array now but there's still error. Can you help me check the codes cos i don't know where have i gone wrong.

    Please Login or Register  to view this content.

  5. #5
    Forum Expert romperstomper's Avatar
    Join Date
    08-13-2008
    Location
    East Sussex, UK
    MS-Off Ver
    365, varying versions/builds
    Posts
    21,274

    Re: Compile Error. Sub of Function not Defined.

    Firstly, if you get an error, it would help if you specified what error and on what line.
    The most obvious thing is that you use .Find but you don't have a With ...End With block. Change this:
    Please Login or Register  to view this content.
    to this:
    Please Login or Register  to view this content.
    and see if that helps.
    Remember what the dormouse said
    Feed your head

  6. #6
    Registered User
    Join Date
    07-14-2009
    Location
    London
    MS-Off Ver
    Excel 2003
    Posts
    32

    Re: Compile Error. Sub of Function not Defined.

    I've changed the code but the problem still lies on this line

    Please Login or Register  to view this content.

  7. #7
    Forum Expert romperstomper's Avatar
    Join Date
    08-13-2008
    Location
    East Sussex, UK
    MS-Off Ver
    365, varying versions/builds
    Posts
    21,274

    Re: Compile Error. Sub of Function not Defined.

    Sorry, not enough coffee yet. Try this:
    Please Login or Register  to view this content.
    Note that the loop through FoundCells is pointless really since you will only ever have found one cell in each loop with this code.
    Last edited by romperstomper; 07-15-2009 at 03:33 AM.

  8. #8
    Registered User
    Join Date
    07-14-2009
    Location
    London
    MS-Off Ver
    Excel 2003
    Posts
    32

    Re: Compile Error. Sub of Function not Defined.

    Thanks for your time, really.

    So are you suggesting that the variable MyArray should be removed since the loop through FoundCells is redundant?

  9. #9
    Forum Expert romperstomper's Avatar
    Join Date
    08-13-2008
    Location
    East Sussex, UK
    MS-Off Ver
    365, varying versions/builds
    Posts
    21,274

    Re: Compile Error. Sub of Function not Defined.

    No, that loop is fine. It's this one that serves no real purpose:
    Please Login or Register  to view this content.
    since FoundCells is only one cell anyway.

  10. #10
    Registered User
    Join Date
    07-14-2009
    Location
    London
    MS-Off Ver
    Excel 2003
    Posts
    32

    Re: Compile Error. Sub of Function not Defined.

    Hi again I adjusted the codes to find the range of data with active cells but when doing so, a run time error occur. (in red font) Are there anyone willing to help.?

    Please Login or Register  to view this content.

  11. #11
    Forum Expert romperstomper's Avatar
    Join Date
    08-13-2008
    Location
    East Sussex, UK
    MS-Off Ver
    365, varying versions/builds
    Posts
    21,274

    Re: Compile Error. Sub of Function not Defined.

    What is the actual error? Do you have a range named 'NumbersX' where X is whatever the value of Rcount is when the error occurs?

  12. #12
    Registered User
    Join Date
    07-14-2009
    Location
    London
    MS-Off Ver
    Excel 2003
    Posts
    32

    Re: Compile Error. Sub of Function not Defined.

    The range that i want to appear on Sheet 2 are the values from range F7:Q13. But before that i will have to declare the rows and find which rows have data in the cell. Eg for the row on month Feb, I dont have any data in the cell. So when i click on the active cell in the row of Feb, a message will display on sheet 2 "No cell found". For active cells which have values will will appear on the cells in sheet 2. Is there a way i can use dynamic array to achieve it?
    Last edited by momo123; 07-15-2009 at 10:46 PM.

  13. #13
    Forum Expert romperstomper's Avatar
    Join Date
    08-13-2008
    Location
    East Sussex, UK
    MS-Off Ver
    365, varying versions/builds
    Posts
    21,274

    Re: Compile Error. Sub of Function not Defined.

    Do you think you could post a sample workbook? I'm finding it difficult to follow exactly what it is you want the code to do.

  14. #14
    Registered User
    Join Date
    07-14-2009
    Location
    London
    MS-Off Ver
    Excel 2003
    Posts
    32

    Re: Compile Error. Sub of Function not Defined.

    It's alright romperstomper, I re-edited the entire code. I really appreciate your help especially when you solved the previous problem that I encountered. Thanks alot!! I'll post up more queries if I encounter any. Thanks again!=)

+ 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