Private Sub CommandButton1_Click()

    Dim rowCount As Long

    'Range("A2")=UserForm1.TextBox1.Value
    'Range("B2")=UserForm1.ComboBox1.Value
    'Range("C2")=UserForm1.TextBox2.Value
    'Range("D2")=UserForm1.TextBox3.Value
    'Range("E2")=UserForm1.ComboBox2.Value
    'Range("F2")=UserForm1.OptionButton1.Value
    'Range("G2") UserForm1.OptionButton2.Value
    'Range("H2")=UserForm1.OptionButton3.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

Recommended Answers

All 2 Replies

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.

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.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.