PDA

View Full Version : [SOLVED:] Variable Not Defined, Excel 2013 & 2007



davis1118
02-24-2018, 09:30 AM
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.

SamT
02-24-2018, 10:32 AM
If you rename the control on the sheet, you have to change the control's Name in the Code.

Paul_Hossler
02-24-2018, 11:46 AM
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

davis1118
02-24-2018, 12:41 PM
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.

21692

davis1118
02-25-2018, 04:45 PM
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.