+ Reply to Thread
Results 1 to 8 of 8

how to call a function, and send across a worksheet object

  1. #1
    Registered User
    Join Date
    12-18-2012
    Location
    singapore
    MS-Off Ver
    Excel 2010
    Posts
    19

    how to call a function, and send across a worksheet object

    Hi, i would like to find out how to send across a worksheet object when calling a function.

    My codes are as follows

    ___________________________________________
    Private Sub EditUserCommandButton_Click()

    Dim ws As worksheet

    Set ws = ThisWorkbook.Sheets("LogInDataBase")

    lastline (ws)
    ____________________________________________


    Public Function lastline(ByVal ws As worksheet) As Integer



    End Function
    ____________________________________________


    when i run the program, it stops on the line in which i call the function, and displays run time error 438. object doesnt support this property or method


    also, can i find out how to initialize the value of the following string

    hello"" my name is xxx

    string = "hello""my name is xxx"

    the additional quotes within my string is causing a problem. how do i tell the editor that the quotes are part of my string.


    Thank you

  2. #2
    Forum Expert OllieB's Avatar
    Join Date
    12-20-2012
    Location
    Netherlands
    MS-Off Ver
    Excel 2007 (home) & 2010 (office)
    Posts
    1,542

    Re: how to call a function, and send across a worksheet object

    Your function is defined as returning an integer so the statement

    Please Login or Register  to view this content.
    is not permissible as there is no place to store the returned integer value. Use either of the two possibilities below

    Please Login or Register  to view this content.
    With regards to the quotes question, I am not really sure what you are trying to achieve. If you want to use quotes in your text then using Chr$(34) is easier than using the " character itself
    If you like my contribution click the star icon!

  3. #3
    Forum Guru JosephP's Avatar
    Join Date
    03-27-2012
    Location
    Ut
    MS-Off Ver
    2003/10
    Posts
    7,328

    Re: how to call a function, and send across a worksheet object

    you can also remove the parentheses
    Please Login or Register  to view this content.
    if you are not interested in the return value
    Josie

    if at first you don't succeed try doing it the way your wife told you to

  4. #4
    Forum Contributor
    Join Date
    12-27-2012
    Location
    cebu, Philippines
    MS-Off Ver
    Excel 2016
    Posts
    210

    Re: how to call a function, and send across a worksheet object

    Hi aaronkoh,
    about this part


    Quote Originally Posted by aaronkoh View Post

    when i run the program, it stops on the line in which i call the function, and displays run time error 438. object doesnt support this property or method


    also, can i find out how to initialize the value of the following string

    hello"" my name is xxx

    string = "hello""my name is xxx"

    the additional quotes within my string is causing a problem. how do i tell the editor that the quotes are part of my string.


    Thank you


    if you want the name "xxx" replaceable

    then you do this:
    -----------------------------------------

    Sub greeting()
    dim greetstring, namestring as string
    greetstring = "Hello, My name is "
    namestring = "aaronkoh"
    msgbox (greetstring & namestring)
    end sub


    ------------------------------------------

    the qoutations (aka speechmarks) - "" - are only required if you're refering to the actual words you want to appear. the words have to be inside the speechmarks
    *try and run the macro i have above and have fun with it
    don't worry, there's a lot of people that are far more confused than you
    but if you liked what i suggested. Click for me the "Add Reputation" - that way, we'd be both happy.

  5. #5
    Registered User
    Join Date
    12-18-2012
    Location
    singapore
    MS-Off Ver
    Excel 2010
    Posts
    19

    Re: how to call a function, and send across a worksheet object

    Hi, i have tried making the following, but it still gives back the same error.

    what i am trying to do is to pass the worksheet object over to a function. the function will then work with reference to the data on this worksheet, and finally return an integer.

    Private Sub EditUserCommandButton_Click()

    Dim ws As Worksheet
    Dim result As Integer

    Set ws = ThisWorkbook.Sheets("LogInDataBase")

    result = lastline(ws)

    End Sub

  6. #6
    Forum Guru JosephP's Avatar
    Join Date
    03-27-2012
    Location
    Ut
    MS-Off Ver
    2003/10
    Posts
    7,328

    Re: how to call a function, and send across a worksheet object

    please add code tags to your post

  7. #7
    Registered User
    Join Date
    12-18-2012
    Location
    singapore
    MS-Off Ver
    Excel 2010
    Posts
    19

    Re: how to call a function, and send across a worksheet object

    Hi, the code worked. thanks. the reason is i forgot to change the function variable type back from string to integer.

    Thank you all.


    Also, for the second problem, what i am trying to achieveis to allow for the initializing of a string.

    the string content, however is to include characters such as ""

    e.g. string = "this string attempts to include symbols such as "" within the string"

  8. #8
    Forum Guru JosephP's Avatar
    Join Date
    03-27-2012
    Location
    Ut
    MS-Off Ver
    2003/10
    Posts
    7,328

    Re: how to call a function, and send across a worksheet object

    please add code tags to your posts

+ 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