IF Then Statement to print data onto another worksheet

Dunner72

New Member
Joined
Aug 31, 2014
Messages
3
Hi I am making a classroom Attendance Tracker on Excel 2013.

I am using VBA to make a userform to enter Data.
I currently, I am able to code the userform to enter data onto the next available row of my active worksheet. However, I want a Checkbox, that when checked, will also enter the data onto the next available row of a second worksheet. I don't know how to code for that.
Here is what I have so far:
Private Sub cmdAdd_Click()
Dim i As Integer
Range("AI6").Select
i = 1
Do Until ActiveCell.Value = Empty
ActiveCell.Offset(1, 0).Select 'move down 1 row
Loop


'Populate the data values into the 'current' worksheet.

ActiveCell.Offset(0, 0).Value = Me.txtDate.Text 'set col B
ActiveCell.Offset(0, 1).Value = Me.cboOccurence.Text 'set col C
ActiveCell.Offset(0, 2).Value = Me.cboReason.Text 'set col D

If CheckBox1.Value = True Then


WHERE DO I GO FROM HERE ? If Checkbox1 is true, then I want to enter the same data onto another worksheet called "Admissions"
 

Excel Facts

What is =ROMAN(40) in Excel?
The Roman numeral for 40 is XL. Bill "MrExcel" Jelen's 40th book was called MrExcel XL.
How about this?
Code:
Private Sub cmdAdd_Click()
    Dim i As Integer
    Dim MyRng As Range

    Range("AI6").Select
    i = 1
    Do Until ActiveCell.Value = Empty
        ActiveCell.Offset(1, 0).Select 'move down 1 row
    Loop


    'Populate the data values into the 'current' worksheet.

    ActiveCell.Offset(0, 0).Value = Me.txtDate.Text 'set col B
    ActiveCell.Offset(0, 1).Value = Me.cboOccurence.Text 'set col C
    ActiveCell.Offset(0, 2).Value = Me.cboReason.Text 'set col D

    If CheckBox1.Value = True Then
        Set MyRng = Worksheets("Admissions").Range("AI" & Rows.Count).End(xlUp).Offset(1)
        MyRng.Value = Me.txtDate.Text
        MyRng.Offset(, 1).Value = Me.cboOccurence.Text
        MyRng.Offset(, 2).Value = Me.cboReason.Text
    End If

End Sub
You haven't said where on the admissions sheet you want the data so I have used column AI as per your code for the active sheet.
Although I am slightly confused by that, as you comments refer to columns B,C & D?
 
Upvote 0
Thanks for your reply, Fluff.
Sorry for the confusion with columns A, B, and C. I had used that in some earlier attempts, and I forgot to take it out before pasting it onto this forum.

On my "admissions" worksheet, I wanted the data to appear beginning at B3; not beginningi at "AI" like the active sheet.
When I try changing the new location onto your line of code here:
Set MyRng = Worksheets ("Admissions").Range("B3" & Rowths.Count)End(xlUp).Offset(1)
it throws an error code.

"Run-time error 1004;
application-defined or object-defined error"

Do you know how I can fix that?
 
Upvote 0
Code:
Set MyRng = Worksheets ("Admissions").Range("B3" & Rowths.Count)[COLOR=#ff0000].[/COLOR]End(xlUp).Offset(1)
You've need a full stop in front of End
 
Upvote 0

Forum statistics

Threads
1,226,227
Messages
6,189,748
Members
453,567
Latest member
kentbarbie

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