+ Reply to Thread
Results 1 to 9 of 9

Variable not defined error when I have defined the variable

  1. #1
    Registered User
    Join Date
    08-01-2012
    Location
    Charlotte, NC
    MS-Off Ver
    Excel 2010
    Posts
    8

    Variable not defined error when I have defined the variable

    I am having an issue where I am getting a "variable not defined" error but the variable has been defined (and defined correctly). VBA even autocorrects it when I input a lower case letter so it is definitely recognizing the variable but for some reason cannot compile when I run the macro. I had no issues with this document until recently but I have been adding code of the last few weeks. Anybody seen this issue before or have any suggestions to fix? The declaration and defining variables portion so my code is below. I get this same error for all the variables.

    Please Login or Register  to view this content.

  2. #2
    Forum Expert Tinbendr's Avatar
    Join Date
    06-26-2012
    Location
    USA
    MS-Off Ver
    Office 2010
    Posts
    2,125

    Re: Variable not defined error when I have defined the variable

    When you declare variables on the same line;
    Please Login or Register  to view this content.
    The first one is declared as Variant, not a Long.
    The correct way on the same line:
    Please Login or Register  to view this content.
    David
    (*) Reputation points appreciated.

  3. #3
    Registered User
    Join Date
    08-01-2012
    Location
    Charlotte, NC
    MS-Off Ver
    Excel 2010
    Posts
    8

    Re: Variable not defined error when I have defined the variable

    David,

    Thanks for the help. I went through and did this and it is still not picking up any of my defined variables. I have 2 other userforms that have this same code that have no issues so I am not sure what is happening with this one. It almost seems that I have somehow disabled the ability to dimensionalize variables. Is that even possible?

  4. #4
    Valued Forum Contributor
    Join Date
    05-07-2012
    Location
    USA
    MS-Off Ver
    Excel 2007
    Posts
    354

    Re: Variable not defined error when I have defined the variable

    what is not defined?

    for example

    Please Login or Register  to view this content.
    are you getting error because txtDate2 is not defined? (add watch for txtDate2 to find out)
    Regards,
    Vandan

  5. #5
    Registered User
    Join Date
    08-01-2012
    Location
    Charlotte, NC
    MS-Off Ver
    Excel 2010
    Posts
    8

    Re: Variable not defined error when I have defined the variable

    No. I am sorry - I realize my post is a little confusing.

    I have dimensionalized Date1 as a date but when I go to run the macro I get an error stating "variable not defined" with Date1 highlighted. So it is not recognizing Date1 as a defined variable.

  6. #6
    Valued Forum Contributor
    Join Date
    05-07-2012
    Location
    USA
    MS-Off Ver
    Excel 2007
    Posts
    354

    Re: Variable not defined error when I have defined the variable

    can you upload your file so we can help more effectively?

  7. #7
    Registered User
    Join Date
    08-01-2012
    Location
    Charlotte, NC
    MS-Off Ver
    Excel 2010
    Posts
    8

    Re: Variable not defined error when I have defined the variable

    Sure. Here is the full code. I have a userform that people are inputting data. This particular code goes with a command button that enters downtime information from a manufacturing process into an Excel spreadsheet. I get a error message stating "variable not defined" for every variable I have defined. I tried commenting out one variable at a time to see if the other variables would work but I get the same error for all.

    Please Login or Register  to view this content.

  8. #8
    Valued Forum Contributor
    Join Date
    05-07-2012
    Location
    USA
    MS-Off Ver
    Excel 2007
    Posts
    354

    Re: Variable not defined error when I have defined the variable

    Nothing obvious comes to mind except may be type conversion error.

    does changing

    Please Login or Register  to view this content.
    to

    Please Login or Register  to view this content.
    help for this one particular variable? If it does, you might have to type cast all variables (it is a good practice anyway)

    if not, can you upload your entire excel file? If you can't for proprietary reasons, let me know, and I will ask brighter minds to look.

  9. #9
    Forum Expert mikerickson's Avatar
    Join Date
    03-30-2007
    Location
    Davis CA
    MS-Off Ver
    Excel 2011
    Posts
    6,229

    Re: Variable not defined error when I have defined the variable

    I have 2 other userforms that have this same code
    Have you defined each of the variables in each of the code modules (1 code module per userform)?
    _
    ...How to Cross-post politely...
    ..Wrap code by selecting the code and clicking the # or read this. Thank you.

+ 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