Add data from UserForm to next empty column

hannahfo

New Member
Joined
Nov 15, 2018
Messages
3
I'm relatively new to VBA but I am writing a code that basically brings up a Userform with CheckBoxes. Each employee is supposed to open up and submit their form each week. I have an If code set up and an automatic date stamp for the worksheet, but how to I make it so the column switched to the next open one with each submission, instead of over writing the data already submitted.

Here is my code so far:

Code:
Private Sub CommandButton1_Click()

Range("B1").Value = Now()


If CheckBox1.Value = True Then
Sheet2.Range("B2").Value = ""
Else
Sheet2.Range("B2").Value = "X"
End If


If CheckBox2.Value = True Then
Sheet2.Range("B3").Value = ""
Else
Sheet2.Range("B3").Value = "X"
End If


If CheckBox3.Value = True Then
Sheet2.Range("B4").Value = ""
Else
Sheet2.Range("B4").Value = "X"
End If
 

Excel Facts

Format cells as date
Select range and press Ctrl+Shift+3 to format cells as date. (Shift 3 is the # sign which sort of looks like a small calendar).
Is it definitely the next empty column?

If it is try this.
Code:
Private Sub CommandButton1_Click()
Dim rng As Range
    
    Set rng = Sheet2.Cells(1, Columns.Count).End(xlToLeft).Offset(, 1)
        
    With rng
        .Value = Now()
        .Offset(1).Value = IIf(CheckBox1.Value, "X", "")        
        .Offset(2).Value = IIf(CheckBox2.Value, "X", "")
        .Offset(3).Value = IIf(CheckBox3.Value, "X", "")
    End With

End Sub
 
Last edited:
Upvote 0
Works fine for me, where do you get the error?
 
Upvote 0
Fixed the error code but now nothing is coming up in the worksheet when I test the code.

Here is what I have including all Checkboxes.

Code:
Private Sub CommandButton1_Click()Dim rng As Range
    
    Set rng = Sheet2.Cells(1, Columns.Count).End(xlToLeft).Offset(0, 1)
        
    With rng
        .Value = Now()
        .Offset(1).Value = IIf(CheckBox1.Value, "", "X")
        .Offset(2).Value = IIf(CheckBox2.Value, "", "X")
        .Offset(3).Value = IIf(CheckBox3.Value, "", "X")
        .Offset(4).Value = IIf(CheckBox4.Value, "", "X")
        .Offset(5).Value = IIf(CheckBox5.Value, "", "X")
        .Offset(6).Value = IIf(CheckBox13.Value, "", "X")
        .Offset(7).Value = IIf(CheckBox12.Value, "", "X")
        .Offset(8).Value = IIf(CheckBox16.Value, "", "X")
        .Offset(9).Value = IIf(CheckBox9.Value, "", "X")
        .Offset(10).Value = IIf(CheckBox14.Value, "", "X")
    End With


End Sub
 
Upvote 0

Forum statistics

Threads
1,223,239
Messages
6,170,947
Members
452,368
Latest member
jayp2104

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