PDA

View Full Version : [SOLVED] Variable Not Defined Error



yojoe266
12-04-2017, 02:44 PM
Hi, I'm making a combobox that would auto populate a couple textboxes based on the dropdown menu selection and I keep getting a variable not defined error and I don't know why. I thought I had defined everything. Any help would be nice thanks! : pray2:


Option Explicit
Private Sub cmbNumber_DropButtonClick()

Dim i As Long, LastRow As Long
LastRow = Sheets("Data").Range("A" & Rows.Count).End(xlUp).Row
If Me.cmbNumber.ListCount = 0 Then
For i = 2 To LastRow
Me.cmbNumber.AddItem Sheets("Data").Cells(i, "A").Value
Next i
End If

End Sub


Private Sub cmbNumber_Change()
Dim i As Long
Dim LastRow As Long

LastRow = Sheets("Data").Range("A" & Rows.Count).End(xlUp).Row

For i = 2 To LastRow
If Sheets("Data").Cells(i, "A").Value = (Me.cmbNumber) Or _
Sheets(“Data”).Cells(i, “A”).Value = Val(Me.cmbNumber) Then
Me.TextBox1 = Sheets("Data").Cells(i, "B").Value
Me.TextBox2 = Sheets("Data").Cells(i, "C").Value
End If
Next
End Sub

snb
12-04-2017, 03:17 PM
See

http://www.snb-vba.eu/VBA_Fill_combobox_listbox_en.html

Kenneth Hobs
12-04-2017, 03:22 PM
Please paste code between code tags. Click # icon to insert the tags.

Change slant double quotes to straight double quotes.

SamT
12-04-2017, 03:29 PM
What Line does the error occur on?

yojoe266
12-04-2017, 03:35 PM
What Line does the error occur on?

It occurs on Private Sub cmbNumber_Change().

Paul_Hossler
12-04-2017, 04:12 PM
Replace the 'smart' (aka curly) quotes with VBA quotes

Instead of



(“Data”).Cells(i, “A”).



use



("Data").Cells(i, "A").


and see if that helps

yojoe266
12-04-2017, 04:22 PM
Replace the 'smart' (aka curly) quotes with VBA quotes

Instead of



(“Data”).Cells(i, “A”).



use



("Data").Cells(i, "A").


and see if that helps


Wow surprisingly, that actually solved the issue. Thanks!