+ Reply to Thread
Results 1 to 17 of 17

Function returning error

  1. #1
    Forum Contributor
    Join Date
    09-03-2008
    Location
    Somerset, England
    MS-Off Ver
    XP, 2003, 2007 - depends on location
    Posts
    185

    Function returning error

    Hi all,

    I have a function that works out which is the last column containing data on a worksheet, but for some reason it is alwys retuning 0. Just wondering if anybody is able to spot where I am going wrong.

    Here is the function I am using -

    Please Login or Register  to view this content.
    And here are the ways I have tried retrieving data from the function, all of which return 0 -

    Please Login or Register  to view this content.
    When I take the Error handleing out I am getting the error 'Object Variable or With Block Variable not set'. All variables are correctly declered.

    Any help is greatly appriciated.
    Thanks.

  2. #2
    Forum Expert shg's Avatar
    Join Date
    06-20-2007
    Location
    The Great State of Texas
    MS-Off Ver
    2003, 2010
    Posts
    40,678

    Re: Function returning error

    So you single-step through the code and what happens?
    Entia non sunt multiplicanda sine necessitate

  3. #3
    Forum Contributor
    Join Date
    09-03-2008
    Location
    Somerset, England
    MS-Off Ver
    XP, 2003, 2007 - depends on location
    Posts
    185

    Re: Function returning error

    If I leave the error handlers in the Function, noting happens, but LastColumn is returned as 0 (as set if 'Error <> 0'). But if I remove that that I get an error (Run-time error '91';, which is the one mentioned above) the first time I go into the meat of the function.

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

    Re: Function returning error

    Do you actually have any data in the sheets you are testing on?
    Remember what the dormouse said
    Feed your head

  5. #5
    Forum Contributor
    Join Date
    09-03-2008
    Location
    Somerset, England
    MS-Off Ver
    XP, 2003, 2007 - depends on location
    Posts
    185

    Re: Function returning error

    I do indeed have data (Far to much if you ask me!!), I have checked that 'wS22' is the currently selected sheet, and the the correct workbook is selected, but still no joy

  6. #6
    Forum Expert shg's Avatar
    Join Date
    06-20-2007
    Location
    The Great State of Texas
    MS-Off Ver
    2003, 2010
    Posts
    40,678

    Re: Function returning error

    ws22 as you're using it in the code (ws22.Name) is the CodeName of the sheet, not the sheet name (unless they're the same).

  7. #7
    Forum Contributor
    Join Date
    09-03-2008
    Location
    Somerset, England
    MS-Off Ver
    XP, 2003, 2007 - depends on location
    Posts
    185

    Re: Function returning error

    They are both the same, but I have also tried to manually assign the name of the sheet to a variable and then checked using the variable as the sheet name, but still get 0 returned.

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

    Re: Function returning error

    Where is the function code located? I cannot replicate what you are seeing - I get column numbers if there is data in the sheet.

  9. #9
    Forum Contributor
    Join Date
    09-03-2008
    Location
    Somerset, England
    MS-Off Ver
    XP, 2003, 2007 - depends on location
    Posts
    185

    Re: Function returning error

    Hmm, thats random. The function is located at the bottom of a Module called 'Functions'. I have tried to run the function from both inside and outside the Module that contains it, using both public and local variables, each time I get '0' returned.

    This may be completely wrong, but as it is declared as a Public Function, it should matter where it is located, should it?

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

    Re: Function returning error

    I wanted to make sure it was in a normal module, not a class module.
    It appears the Find is not working - have you done any finds involving searching formats?

  11. #11
    Forum Contributor
    Join Date
    09-03-2008
    Location
    Somerset, England
    MS-Off Ver
    XP, 2003, 2007 - depends on location
    Posts
    185

    Re: Function returning error

    Ah, Ok. Do you mean have I used Find at any other point in the code? If yes, then no, this is the only occurance of it.

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

    Re: Function returning error

    Doesn't have to be in code. If you have done a Find in the UI, those settings will be used unless your code overrides them specifically.

  13. #13
    Forum Contributor
    Join Date
    09-03-2008
    Location
    Somerset, England
    MS-Off Ver
    XP, 2003, 2007 - depends on location
    Posts
    185

    Re: Function returning error

    You'll have to excuse my noobness here, but what is 'UI', and how would I override the setting in the code?

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

    Re: Function returning error

    When using Find it is best to specify every parameter, including the optional ones, to ensure you are getting the Find you think you are!
    UI = User Interface.

  15. #15
    Forum Contributor
    Join Date
    09-03-2008
    Location
    Somerset, England
    MS-Off Ver
    XP, 2003, 2007 - depends on location
    Posts
    185

    Re: Function returning error

    Well, I do have a couple of Forms that are used before this function is called, but neither of them use Find at all. I have specified every paramiter for find and I am still getting 0! I am going to scratch my head for the night and come back to this tomorrow. Thanks for the help up til now.

  16. #16
    Forum Expert shg's Avatar
    Join Date
    06-20-2007
    Location
    The Great State of Texas
    MS-Off Ver
    2003, 2010
    Posts
    40,678

    Re: Function returning error

    I have specified every paramiter for find ...
    .Find(What, After, LookIn, LookAt, SearchOrder, SearchDirection, MatchCase, MatchByte, SearchFormat)

  17. #17
    Forum Contributor
    Join Date
    09-03-2008
    Location
    Somerset, England
    MS-Off Ver
    XP, 2003, 2007 - depends on location
    Posts
    185

    Re: Function returning error

    I cheated in the end and went for this, as it is only going to be used once in the code. Thanks for your help.

    Please Login or Register  to view this content.

+ 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