+ Reply to Thread
Results 1 to 12 of 12

Compile Error Variable Not Defined when trying to submit a VBA Userform

  1. #1
    Forum Contributor
    Join Date
    07-03-2019
    Location
    Victoria, Australia
    MS-Off Ver
    Office 365
    Posts
    126

    Compile Error Variable Not Defined when trying to submit a VBA Userform

    Hi Excel Forum,

    I have written some VBA Code and have worked out most of the issues i was having but i now have a Compile error Variable not defined coming up.

    I have a userform and when i hit submit it is coming up with the error. I have a combobox1 dropdown which has locations in it and i want it to go onto that sheet along with other textboxes and comboboxes i want to go into certain cells on the sheet as well that i'm not sure if that is causing the issue or it something else.

    Sorry no sample file available hopefully you are able to help from the code below

    Please Login or Register  to view this content.
    TIA
    Donald Harvey

  2. #2
    Administrator 6StringJazzer's Avatar
    Join Date
    01-27-2010
    Location
    Tysons Corner, VA, USA
    MS-Off Ver
    MS365 Family 64-bit
    Posts
    24,662

    Re: Compile Error Variable Not Defined when trying to submit a VBA Userform

    When asking help with an error, always indicate the line of the code that is highlighted when the error occurs. Otherwise we are looking for a needle in a haystack.
    Jeff
    | | |會 |會 |會 |會 | |:| | |會 |會
    Read the rules
    Use code tags to [code]enclose your code![/code]

  3. #3
    Forum Expert torachan's Avatar
    Join Date
    12-27-2012
    Location
    market harborough, england
    MS-Off Ver
    Excel 2010
    Posts
    4,302

    Re: Compile Error Variable Not Defined when trying to submit a VBA Userform

    Try altering one or both lines to below.
    Failing that see big yellow banner - upload your workbook - remove sensitive data.


    Please Login or Register  to view this content.
    Torachan,

    Mission statement; Promote the use of Tables, Outlaw the use of 'merged cells' and 'RowSource'.

  4. #4
    Administrator 6StringJazzer's Avatar
    Join Date
    01-27-2010
    Location
    Tysons Corner, VA, USA
    MS-Off Ver
    MS365 Family 64-bit
    Posts
    24,662

    Re: Compile Error Variable Not Defined when trying to submit a VBA Userform

    Quote Originally Posted by torachan View Post
    Please Login or Register  to view this content.
    I think you need to omit the quotes, that's a variable name

    Please Login or Register  to view this content.

  5. #5
    Forum Expert rorya's Avatar
    Join Date
    08-13-2008
    Location
    East Sussex, UK
    MS-Off Ver
    365 Ent Monthly Channel / Insiders Beta
    Posts
    8,901

    Re: Compile Error Variable Not Defined when trying to submit a VBA Userform

    Shouldn't you be using shSheet, not sh? Also, there's no point to something like "B" + 2 when you can just use "B2"
    Rory

  6. #6
    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
    44,299

    Re: Compile Error Variable Not Defined when trying to submit a VBA Userform

    Suspect this
    Please Login or Register  to view this content.
    should be this
    Please Login or Register  to view this content.
    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


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

    Re: Compile Error Variable Not Defined when trying to submit a VBA Userform

    in addition you probably want to replace the fixed reference to row 2 with the last row number you load in to the variable iCurrentRow.
    As well as removing the sh reference within the WITH block. and finishing that block using END WITH instead of END IF

    Please Login or Register  to view this content.
    Cheers
    Andy
    www.andypope.info

  8. #8
    Forum Contributor
    Join Date
    07-03-2019
    Location
    Victoria, Australia
    MS-Off Ver
    Office 365
    Posts
    126

    Re: Compile Error Variable Not Defined when trying to submit a VBA Userform

    Hi,

    I have made the changes i think mentioned above now when i submit it comes up with a Run-Time error 13: Type Mismatch when i cllick debug it highlight this section
    Please Login or Register  to view this content.
    I have also attached a sample workbook as well

    the full code is now
    Please Login or Register  to view this content.
    Attached Files Attached Files

  9. #9
    Forum Expert rorya's Avatar
    Join Date
    08-13-2008
    Location
    East Sussex, UK
    MS-Off Ver
    365 Ent Monthly Channel / Insiders Beta
    Posts
    8,901

    Re: Compile Error Variable Not Defined when trying to submit a VBA Userform

    You need:

    Please Login or Register  to view this content.

  10. #10
    Forum Contributor
    Join Date
    07-03-2019
    Location
    Victoria, Australia
    MS-Off Ver
    Office 365
    Posts
    126

    Re: Compile Error Variable Not Defined when trying to submit a VBA Userform

    Hi,

    I can see its now adding it into the spreadsheet, but when you go to add another entry it is overriding the previous entry, I want it to be on the next line down and so on for each entry after.

    Thanks

  11. #11
    Forum Expert rorya's Avatar
    Join Date
    08-13-2008
    Location
    East Sussex, UK
    MS-Off Ver
    365 Ent Monthly Channel / Insiders Beta
    Posts
    8,901

    Re: Compile Error Variable Not Defined when trying to submit a VBA Userform

    It appears you aren't populating column A so you should use B to calculate the next row:

    Please Login or Register  to view this content.

  12. #12
    Forum Contributor
    Join Date
    07-03-2019
    Location
    Victoria, Australia
    MS-Off Ver
    Office 365
    Posts
    126

    Re: Compile Error Variable Not Defined when trying to submit a VBA Userform

    Thanks Rorya, that has worked for me thanks again.

+ 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. Userform - VBA code compile error: User-defined type not defined
    By rayhee1985 in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 06-14-2020, 11:03 AM
  2. Compile error: Variable not defined
    By jrpuig1977 in forum Excel Programming / VBA / Macros
    Replies: 11
    Last Post: 10-16-2014, 06:55 PM
  3. Compile error: variable not defined
    By jwoodman in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 08-12-2014, 06:52 AM
  4. [SOLVED] Compile Error: Variable Not Defined
    By Limitedtimeonearth in forum Excel Programming / VBA / Macros
    Replies: 14
    Last Post: 06-03-2013, 03:07 PM
  5. Compile Error Variable not Defined
    By Mooseman60 in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 11-16-2010, 10:13 AM
  6. Compile error on variable (not defined)
    By mqdias in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 11-12-2007, 06:47 AM
  7. Compile error: Variable not defined
    By radion in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 01-24-2007, 05:31 PM

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