VBA to enter alternating text

tryingmybest418

New Member
Joined
Jan 22, 2018
Messages
32
Hi all,

I'm creating a timesheet entry system that will log the date/time and either IN or OUT when a button is clicked.
I have the code to log the date/time, but was looking for help entering an alternating IN/OUT text?

For example, if it is the first entry, I'd like A4 to display "IN". On the next click, I'd like A5 to display "OUT". Then A6 "IN", etc.

Is there a simple way to accomplish this?

Thanks!
 

Excel Facts

Save Often
If you start asking yourself if now is a good time to save your Excel workbook, the answer is Yes
We should combine all this in to the same script.

Show us the code you already have.
 
Upvote 0
I have the below so far. I'm just wondering how I can set the line for column A to alternate between "IN" and "OUT" on each click, starting with "IN" if there are no other entries.

Sub timecard()


Range("B" & Rows.Count).End(xlUp).Offset(1).Value = Now


Range("A" & Rows.Count).End(xlUp).Offset(1).Value = ?????

End Sub
 
Last edited:
Upvote 0
Try this:
Code:
Sub Timecard()
'Modified 3-5-18 6:00 PM EST
Application.ScreenUpdating = False
Dim Lastrow As Long
Lastrow = Cells(Rows.Count, "B").End(xlUp).Row + 1
Cells(Lastrow, 2).Value = Now
    If Cells(Lastrow, 1).Offset(-1, 0).Value = "IN" Then
        Cells(Lastrow, 1).Value = "OUT"
    Else
        Cells(Lastrow, 1).Value = "IN"
    End If
Application.ScreenUpdating = True
End Sub
 
Upvote 0

Forum statistics

Threads
1,224,823
Messages
6,181,178
Members
453,021
Latest member
Justyna P

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