Consulting

Results 1 to 3 of 3

Thread: Cannot pass object to sub-procedure located in worksheet?

  1. #1
    VBAX Newbie
    Joined
    Feb 2019
    Posts
    2
    Location

    Cannot pass object to sub-procedure located in worksheet?

    Hi,
    I spent a lot of time looking for a solution but with no luck.

    I have created class CWpis in my 'Class Modules'. In 'Forms' i created sub procedure that collects data
    from textboxes and put it to my CWpis new object. Then, I want to pass this object to sub-procedure
    located in another worksheet:

        Sub CommandButton1_Click()
    
            Dim aaa As New CWpis    
            aaa.NumberUD = TextBox1.Value
    
            Worksheets("Main").NewUD aaa
    
        End Sub
    This is sub-procedure in worksheet "main":

        Public Sub NewUD(ByRef nUD As CWpis)
    
            Debug.Print (nUD.NumberUD)
    
        End Sub
    What do I get is:
    "Run-time error '40036':
    Application-defined or object-defined error"

    I can pass the same object to sub-procedure located in modules but cannot to worksheets? What is the
    reason?

  2. #2
    VBAX Master Aflatoon's Avatar
    Joined
    Sep 2009
    Location
    UK
    Posts
    1,720
    Location
    Which version of Excel?
    Be as you wish to seem

  3. #3
    VBAX Newbie
    Joined
    Feb 2019
    Posts
    2
    Location
    Quote Originally Posted by Aflatoon View Post
    Which version of Excel?
    It's Excel 2013 - VBA 7.1

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •