Consulting

Results 1 to 5 of 5

Thread: Variable Not Defined, Excel 2013 & 2007

  1. #1

    Variable Not Defined, Excel 2013 & 2007

    I have searched on the internet and can't quite find what I need. I have a master template sheet with many toggle buttons, text boxes, and combo boxes. The master sheet gets copied and renamed from a userform. The toggle buttons, text boxes, and combo boxes on the new sheet then get renamed and populated from the userform.

    Everything was working perfectly, until I realized I forgot to use Option Explicit. Now I am getting a Compile Error: Variable Not Defined on multiple ComboBox change events. It either highlights the Private Sub ComboBox1_Change or the TextBox.Value part of the code. I have 10 lines of the ComboBox change events but I only get the compile error on 5 of them.

    The compile error only happens on the newly created sheet when excel is opened, never the master template sheet. Below is one of the ComboBox change events. I feel dumb, because I know there has to be something small I am missing, but I'm at a lose for what I am doing wrong. Especially because after accepting the errors, the worksheet will still function correctly.

    Private Sub ComboBox1_Change()
    ToggleButton1.Caption = ComboBox1.Value
    Process1Box.Value = ComboBox1.Value & " - " & "#" & TextBox1.Value
    End Sub
    Also, I am using Excel 2013 at work, and at home I have 2007. I am getting the same error on both versions.

    Thanks for the help.

  2. #2
    Moderator VBAX Sage SamT's Avatar
    Joined
    Oct 2006
    Location
    Near Columbia
    Posts
    7,814
    Location
    If you rename the control on the sheet, you have to change the control's Name in the Code.
    I expect the student to do their homework and find all the errrors I leeve in.


    Please take the time to read the Forum FAQ

  3. #3
    VBAX Sage
    Joined
    Apr 2007
    Location
    United States
    Posts
    8,724
    Location
    Quote Originally Posted by davis1118 View Post
    The toggle buttons, text boxes, and combo boxes on the new sheet then get renamed and populated from the userform.
    Do you mean 'Re-named' or 'Re-captioned'?

    For example, in

    ToggleButton1.Caption = ComboBox1.Value
    The 'Name' if the toggle button is "ToggleButton1", but the 'Caption' would be whatever ComboBox1 is Valued at
    ---------------------------------------------------------------------------------------------------------------------

    Paul


    Remember: Tell us WHAT you want to do, not HOW you think you want to do it

    1. Use [CODE] ....[/CODE ] Tags for readability
    [CODE]PasteYourCodeHere[/CODE ] -- (or paste your code, select it, click [#] button)
    2. Upload an example
    Go Advanced / Attachments - Manage Attachments / Add Files / Select Files / Select the file(s) / Upload Files / Done
    3. Mark the thread as [Solved] when you have an answer
    Thread Tools (on the top right corner, above the first message)
    4. Read the Forum FAQ, especially the part about cross-posting in other forums
    http://www.vbaexpress.com/forum/faq...._new_faq_item3

  4. #4
    Sorry, for the confusion. The name of the controls stay the same on each sheet. The togglebutton captions change based on the combobox value. The comboboxes and textboxes names also stay the same, and just their values change. I have attached my file, because I figured it was the easiest way for someone to troubleshoot. For me, there is too much going on to try and explain. But please go easy with the code as this is my first attempt at a larger project, and it's still very much a work in progress. The file should open fine as it is. But if you "add new part" from the admin sheet, then save, close, and reopening the file should give the compile error.

    Product Documents.xlsm

  5. #5
    Update: My workbook used to work with no issues and I started to think about what change I made before it started showing the compile error on startup. I realized that I change the comboboxes from a dropdowncombo to a dropdownlist. I changed all the comboboxes back to a dropdowncombo, and now I no longer get the compile error when excel opens. Does anyone know the reason for this? I know there are quite a few bugs with comboboxes, so I might just put textboxes on the worksheet and keep comboboxes on userforms.

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
  •