Private Sub CommandButton1_Click()

    Dim rowCount As Long

    'Range("G2") UserForm1.OptionButton2.Value

    rowCount = Sheets("Data").Range("A2").CurrentRegion.Rows.Count
    With Sheets("Data").Range("A2")

        .Offset(rowCount, 0) = Now
        .Offset(rowCount, 1) = UserForm1.TextBox1.Value
        .Offset(rowCount, 2) = UserForm1.ComboBox1.Value
        .Offset(rowCount, 3) = UserForm1.TextBox2.Value
        .Offset(rowCount, 4) = UserForm1.TextBox3.Value
        .Offset(rowCount, 5) = UserForm1.ComboBox2.Value

        If UserForm1.OptionButton1.Value Then
            Sheets("Data").Cells(nextrow, 6) = "CITY"
            If UserForm1.OptionButton2.Value Then
                Sheets("Data").Cells(nextrow, 7) = "TALUKA"
                If UserForm1.OptionButton3.Value Then
                    Sheets("Data").Cells(nextrow, 8) = "TANKARA"
                End If

        .Offset(rowCount, 6) = UserForm1.OptionButton1.Value
        .Offset(rowCount, 7) = UserForm1.OptionButton2.Value
        .Offset(rowCount, 8) = UserForm1.OptionButton3.Value

    End With

    Unload UserForm1
End Sub

Edited by Reverend Jim: fixed formatting

4 Years
Discussion Span
Last Post by Reverend Jim

You have 3 "If then" statements where you put the action on the next line. Either put a space and an underscore "_" after the then, or leave the action on the same line, or put an end if after the action.

You get the end with bceause the program is looking for an end if, of which you need 2 before you get to the end with.

Edited by Klahr_R


It also helps if you indent properly. You probably lost all the indentation because you didn't use the Code button to insert the code snippet. I fixed it up for you.

Edited by Reverend Jim

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.