Consulting

Results 1 to 7 of 7

Thread: Variable Not Defined Error

  1. #1
    VBAX Newbie
    Joined
    Oct 2017
    Posts
    5
    Location

    Variable Not Defined Error

    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!

    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
    Last edited by SamT; 12-04-2017 at 03:27 PM.

  2. #2

  3. #3
    VBAX Guru Kenneth Hobs's Avatar
    Joined
    Nov 2005
    Location
    Tecumseh, OK
    Posts
    4,956
    Location
    Please paste code between code tags. Click # icon to insert the tags.

    Change slant double quotes to straight double quotes.

  4. #4
    Moderator VBAX Sage SamT's Avatar
    Joined
    Oct 2006
    Location
    Near Columbia
    Posts
    7,814
    Location
    What Line does the error occur on?
    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

  5. #5
    VBAX Newbie
    Joined
    Oct 2017
    Posts
    5
    Location
    Quote Originally Posted by SamT View Post
    What Line does the error occur on?
    It occurs on Private Sub cmbNumber_Change().

  6. #6
    VBAX Sage
    Joined
    Apr 2007
    Location
    United States
    Posts
    8,729
    Location
    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
    ---------------------------------------------------------------------------------------------------------------------

    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

  7. #7
    VBAX Newbie
    Joined
    Oct 2017
    Posts
    5
    Location
    Quote Originally Posted by Paul_Hossler View Post
    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!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •