# Excel VBA userform:  Sending data to specific Sheet depending on which Option Button selected into empty column



## Strycure12 (Dec 20, 2022)

Hello ,

I was wondering if anyone can help me to include into the code I have place in this thread to look for next empty column as the project I am work needs to preserve past input. As you can see the code it inputs it into any cell practically. I need help placing it in the next empty column. I have tried and exhausted some of the code, but to no avail. Also the code would need to be userform friendly as it will be used in a userform for logging into a sheet.


Thanks in advance!

Here is the code:
Dim SelectedSheet as worksheet
Dim LastRow as Long

If Me.Opt1.Value Then
    Set SelectedSheet = ThisWorkbook.Sheets("Sh1")
Else
    Set SelectedSheet = ThisWorkbook.Sheets("Sh2")
End If

With SelectedSheet
    With .Cells(.Rows.Count,1).End(xlUP).Offset(1,0)
       .Range("A1").Value = Me.Cmb1.Value
       .Range("B1").Value = Me.Txt1.Text
       .Range("C1").Value = IIf(Me.opt1.Value, Me.txt2.text, Me.txt5.Text)
       .Range("D1").Value = IIf(Me.opt1.Value, Me.txt3.text, Me.txt6.Text)
       .Range("E1").Value = IIf(Me.opt1.Value, Me.txt4.text, Me.txt6.Text)
    End With
End With


----------

