+ Reply to Thread
Results 1 to 4 of 4

Private Function within class module/object, can't pass value of range as string

  1. #1
    Registered User
    Join Date
    12-20-2014
    Location
    North America
    MS-Off Ver
    2013
    Posts
    40

    Private Function within class module/object, can't pass value of range as string

    I have the following function in the class module vehrows

    Please Login or Register  to view this content.
    It its called from the alternate constructor of the class

    Please Login or Register  to view this content.
    I get error 91. I then go ahead and place set in front of the statement
    Please Login or Register  to view this content.
    It then states Object Required for sourceVehCell_vehNum.

    I had it combined with another function, the problem did not occur, i.e.

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

  2. #2
    Forum Guru Andy Pope's Avatar
    Join Date
    05-10-2004
    Location
    Essex, UK
    MS-Off Ver
    O365
    Posts
    20,481

    Re: Private Function within class module/object, can't pass value of range as string

    You would use Set in conjunction with objects. The return value is a string therefore uses Let instead. And Let is optional.

    Why do you think you should, or want to, be using Set?
    Cheers
    Andy
    www.andypope.info

  3. #3
    Forum Expert romperstomper's Avatar
    Join Date
    08-13-2008
    Location
    England
    MS-Off Ver
    365, varying versions/builds
    Posts
    21,980

    Re: Private Function within class module/object, can't pass value of range as string

    I don't get that error with your files (after removing the Set). I do note though that you never check to see if your Find operations succeeded before using the found cell, which is bad practice.

    Also note that code like this can fail:

    Please Login or Register  to view this content.
    It needs to be:

    Please Login or Register  to view this content.
    Everyone who confuses correlation and causation ends up dead.

  4. #4
    Registered User
    Join Date
    12-20-2014
    Location
    North America
    MS-Off Ver
    2013
    Posts
    40

    Re: Private Function within class module/object, can't pass value of range as string

    Quote Originally Posted by rorya View Post
    I don't get that error with your files (after removing the Set). I do note though that you never check to see if your Find operations succeeded before using the found cell, which is bad practice.
    Removing set get generates error 91 on my end.

    Please Login or Register  to view this content.
    I use the the debugger, and soruceVehCell is pointing to the correct cell that holds the value, and vba is refusing to pass the value to the string variable. Sheet3 shows what Sheet2 is supposed to look like.

    I the following file (attached to this post), I'm able to assign to do extractOrginalSourceVehNum = sourceVehCell.Offset(, 1).Value, without that error message.

    I even got rid of "As String", in the initial spreadsheet I uploaded, and the same problem still occurs.

    As stated, this function and it's result is meant to be only called within the class module, not outside of it.

    I went ahead and implemented property let and property get
    Please Login or Register  to view this content.
    And I'm getting the same error message, but in a different function

    Please Login or Register  to view this content.
    I think I found the cause.

    In the ClassIntialize Function, I needed to reposition a Property Let/Get function, i.e. exportFileName(expFilePrefixStr) = vehNum

    to below the sourceVehCell_vehNum = extractOrginalSourceVehNum initialization, since the former was calling a function, dependent on the result from the initialization of sourceVehCell_vehNum.

    The debugger was displaying a sourceVeh number that was non-existent in Column A.
    Attached Images Attached Images
    Attached Files Attached Files
    Last edited by excelicus; 08-31-2018 at 05:56 PM.

+ 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. [SOLVED] Can't pass arguments to a declared class object: obj variable or with block not set
    By excelicus in forum Excel Programming / VBA / Macros
    Replies: 8
    Last Post: 08-20-2018, 01:18 PM
  2. [SOLVED] Using Application.Run to call a private sub in a module from ThisWorkbook object
    By Stormin' in forum Excel Programming / VBA / Macros
    Replies: 8
    Last Post: 10-24-2017, 10:47 AM
  3. Pass Boolean in Class Module
    By krishns in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 08-11-2015, 04:38 AM
  4. Trying to use the worksheet object inside a vba class module
    By dbwstein in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 04-07-2015, 09:52 PM
  5. [SOLVED] Importing .BAS to Sheet Object... NOT Class Module?
    By crabby09 in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 12-10-2014, 10:54 AM
  6. [SOLVED] Pass checkbox variable to private module in this workbook.
    By maacmaac in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 12-06-2013, 11:14 AM
  7. To access a previous object via class module
    By Pierre Archambault in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 12-31-2005, 02:51 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