+ Reply to Thread
Results 1 to 6 of 6

Compile error: Sub or Function not defined Error

Hybrid View

  1. #1
    Registered User
    Join Date
    03-30-2014
    Location
    Australia
    MS-Off Ver
    Excel 2003 & 10
    Posts
    30

    Compile error: Sub or Function not defined Error

    Hi

    I have the below code in my userform under a command button named ‘yes’. When I enter data into my userform & click the yes button this error appears – Compile error: Sub or Function not defined

    Does anyone know what I’m missing here?

    Private Sub Yes_Click()
    
    Dim emptyRow As Long
    
    'Make Sheet1 active
    sheet1.Activate
    
    'Determine emptyRow
    Set emptyRow = WorksheetFunction.CountA(Range("A:A")) + 1
    
    'Transfer information
    Cells(emptyRow, 1).Value = NameTextBox.Value
    Cells(emptyRow, 2).Value = SurnameTextBox.Value
    Cells(emptyRow, 3).Value = AgeTextBox.Value
    Cells(emptyRow, 4).Value = NextPaymentTextBox.Value
    Cells(emptyRow, 5).Value = FrequencyComboBox.Value
    
    End Sub
    Thanks

  2. #2
    Forum Expert
    Join Date
    12-10-2006
    Location
    Sydney
    MS-Off Ver
    Office 365
    Posts
    3,565

    Re: Compile error: Sub or Function not defined Error

    Hi there,

    You don't set a long variable that way - use this (where, though you way should work I've also changed the method of how the variable is set as well):

    emptyRow = Cells(Rows.Count, "A").End(xlUp).Row + 1
    HTH

    Robert
    ____________________________________________
    Please ensure you mark your thread as Solved once it is. Click here to see how
    If this post helps, please don't forget to say thanks by clicking the star icon in the bottom left-hand corner of my post

  3. #3
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    48,207

    Re: Compile error: Sub or Function not defined Error

    You use Set for objects, for example:

    Dim sh As Worksheet
    Set sh = ActiveSheet

    Regards, TMS
    Trevor Shuttleworth - Retired Excel/VBA Consultant

    I dream of a better world where chickens can cross the road without having their motives questioned

    'Being unapologetic means never having to say you're sorry' John Cooper Clarke


  4. #4
    Registered User
    Join Date
    03-30-2014
    Location
    Australia
    MS-Off Ver
    Excel 2003 & 10
    Posts
    30

    Re: Compile error: Sub or Function not defined Error

    Thanks

    That worked, however now I have a new error.

    At line
    Cells(emptyRow, 1).Value = TaskTextBox.Value
    the error 'Run-time error '424', Object required' appears.

    What does this mean?

  5. #5
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    48,207

    Re: Compile error: Sub or Function not defined Error

    Presumably it is referring to TaskTextBox. Does that exist?

  6. #6
    Forum Expert
    Join Date
    12-10-2006
    Location
    Sydney
    MS-Off Ver
    Office 365
    Posts
    3,565

    Re: Compile error: Sub or Function not defined Error

    Presumably it is referring to TaskTextBox. Does that exist?
    Yes, I agree - in your posted example you were returning the value of NameTextBox to cell A(emptyRow) so you may have to change the control name for the code to work again.

    HTH

    Robert

+ 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] Compile Error: Sub or Function not Defined
    By grazian2 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 07-02-2013, 04:27 PM
  2. Compile error: Sub or Function not defined
    By Nanga in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 12-23-2011, 11:05 AM
  3. Compile Error: Sub or Function not defined
    By johnmerlino in forum Excel General
    Replies: 3
    Last Post: 10-03-2010, 03:50 PM
  4. Compile Error. Sub of Function not Defined.
    By momo123 in forum Excel Programming / VBA / Macros
    Replies: 13
    Last Post: 07-16-2009, 05:50 AM
  5. Help With - Compile Error: Sub or Function Not Defined
    By MWS in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 03-23-2006, 02:55 PM

Tags for this Thread

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