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

Strycure12

New Member
Joined
Dec 5, 2022
Messages
8
Office Version
  1. 365
  2. 2021
  3. 2019
Platform
  1. Windows
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
 

Excel Facts

What is the last column in Excel?
Excel columns run from A to Z, AA to AZ, AAA to XFD. The last column is XFD.

Forum statistics

Threads
1,223,894
Messages
6,175,252
Members
452,623
Latest member
Techenthusiast

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top