Results 1 to 7 of 7

Thread: Variable not defined error/ Command Button

  1. #1
    New Member
    Join Date
    Aug 2019
    Posts
    5
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Default Variable not defined error/ Command Button

    Happy Friday,
    I'm very familiar with excel, but not so much with VBA. I'm creating a form with drop downs and one "enter" button at the bottom. When I go to test I get a Variable not defined error with PrivateSub CommandButton1_Click() highlited in yellow along with the (x1Down). Help Please


    End Function
    Private Sub CommandButton1_Click()

    Application.ScreenUpdating = False
    Dim iRow As Long

    iRow = Sheets("Data").Range("A2:A1048576").End(x1Down).Row + 1


    If ValidateForm = True Then

    With ThisWorkbook.Sheets("Data")
    .Range("A" & iRow).Value = iRow - 1
    .Range("B" & iRow).Value = monthinspected.Text
    .Range("C" & iRow).Value = Inspector.Text
    .Range("D" & iRow).Value = inspecitontype.Text

    End With
    Call Reset
    Else
    Application.ScreenUpdating = True
    Exit Sub
    End If
    Application.ScreenUpdaitng = True


    End Sub

  2. #2
    MrExcel MVP
    Moderator
    Fluff's Avatar
    Join Date
    Jun 2014
    Location
    Chippenham
    Posts
    28,012
    Post Thanks / Like
    Mentioned
    467 Post(s)
    Tagged
    47 Thread(s)

    Default Re: Variable not defined error/ Command Button

    Hi & welcome to MrExcel.
    It should be xldown (lower case L), not x1down (numeral one)
    - Posting Data try one of these tools
    - Posting guidelines, forum rules and terms of use
    - Read the FAQs

    Running Office 365 on Win 10

  3. #3
    Rules violation
    Join Date
    Jan 2012
    Posts
    912
    Post Thanks / Like
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)

    Default Re: Variable not defined error/ Command Button

    Should it also be up not down?

    Code:
    iRow = Sheets("Data").Cell(Sheets("Data").Rows.Count, "A").End(xlUp).Row + 1
    Last edited by theBardd; Aug 2nd, 2019 at 12:21 PM.

  4. #4
    New Member
    Join Date
    Aug 2019
    Posts
    5
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Default Re: Variable not defined error/ Command Button

    Thank you. I'm apologizing in advance. I believe that worked as that error message is gone. Now I have a pop up after I choose the inspection type and then press the button and a message box Qualification....Please select the inspection type from drop down. It highlites that box in red and populates this long number in the box. I'm not sure where the number comes from as it's a drop down list of text.

    Here is the beginning code:
    Option Explicit


    Function ValidateForm() As Boolean

    monthinspected.BackColor = vbWhite
    Inspector.BackColor = vbWhite
    inspectiontype = vbWhite

    ValidateForm = True

    If monthinspected.Text <> "January" And monthinspected.Text <> "February" And monthinspected.Text <> "March" And monthinspected.Text <> "April" And monthinspected.Text <> "May" And monthinspected.Text <> "June" And monthinspected.Text <> "July" And monthinspected.Text <> "August" And monthinspected.Text <> "September" And monthinspected.Text <> "October" And monthinspected.Text <> "November" And monthinspected.Text <> "December" Then
    MsgBox "Please select the correct month from drop down.,", vbOKOnly + vbInformation, "Qualification"
    monthinspected.BackColor = vbRed
    monthinspected.Activate
    ValidateForm = False

    ElseIf Inspector.Text <> "Chuck" And Inspector.Text <> "Rob" And Inspector.Text <> "Other" Then
    MsgBox "Please select the correct Inspector from drop down.,", vbOKOnly + vbInformation, "Qualification"
    Inspector.BackColor = vbRed
    Inspector.Activate
    ValidateForm = False

    ElseIf inspectiontype.Text <> "Footings" And inspectiontype.Text <> "Foundation" And inspectiontype.Text <> "Underground Plumbing" And inspectiontype.Text <> "Underground Heating" And inspectiontype.Text <> "Framing" And inspectiontype.Text <> "Rough Plumbing" And inspectiontype.Text <> "Rough Heating" And inspectiontype.Text <> "Rough Electric" And inspectiontype.Text <> "Roof" And inspectiontype.Text <> "Electrical Service" And inspectiontype.Text <> "Electrical Temporary" And inspectiontype.Text <> "Final" And inspectiontype.Text <> "Pre Construction Inspection" And inspectiontype.Text <> "Courtesy Inspection" And inspectiontype.Text <> "Unsafe" Then
    MsgBox "Please select the inspection type from drop down.,", vbOKOnly + vbInformation, "Qualification"
    inspectiontype.BackColor = vbRed
    inspectiontype.Activate
    ValidateForm = False
    End If

    End Function
    Last edited by Fluff; Aug 2nd, 2019 at 01:12 PM. Reason: Removed failed image code

  5. #5
    MrExcel MVP
    Moderator
    Fluff's Avatar
    Join Date
    Jun 2014
    Location
    Chippenham
    Posts
    28,012
    Post Thanks / Like
    Mentioned
    467 Post(s)
    Tagged
    47 Thread(s)

    Default Re: Variable not defined error/ Command Button

    As this is now a totally different question, you will need to start a new thread.
    Thanks
    - Posting Data try one of these tools
    - Posting guidelines, forum rules and terms of use
    - Read the FAQs

    Running Office 365 on Win 10

  6. #6
    New Member
    Join Date
    Aug 2019
    Posts
    5
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Default Re: Variable not defined error/ Command Button

    Thank you for your assistance and directions

  7. #7
    MrExcel MVP
    Moderator
    Fluff's Avatar
    Join Date
    Jun 2014
    Location
    Chippenham
    Posts
    28,012
    Post Thanks / Like
    Mentioned
    467 Post(s)
    Tagged
    47 Thread(s)

    Default Re: Variable not defined error/ Command Button

    You're welcome & thanks for the feedback
    - Posting Data try one of these tools
    - Posting guidelines, forum rules and terms of use
    - Read the FAQs

    Running Office 365 on Win 10

Some videos you may like

User Tag List

Tags for this Thread

Like this thread? Share it with others

Like this thread? Share it with others

Posting Permissions

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