Macro Finding First Empty Cell In Column Then Returning Date OR Time

LechlerFan

New Member
Joined
Mar 17, 2017
Messages
1
I have no experience editing macros. I can make two things work individually (sort of) but can't get them to work together.

What I want is to have a button that says, "Start." The associated macro finds the first empty cell in a particular column (let's say column B), selects it, and inserts today's date (using "Ctrl+;"). The same macro would then also find the first empty cell in column C and insert the current time, using "Ctrl+Shift+;".

A second button would say "Stop," with a macro that searches column D for the first empty cell and inserts the current time. I think I can figure out the "Stop" macro if I can get a grip on the "Start."

The result would look like the below, where the "Start" button fills columns B and C, and the "Stop" button fills column D. Bill has not yet clicked the "Stop" button on the 17th, but when he does, it will fill the empty cell in that column. The next time Bill clicks the "Start" button, B5 and C5 will fill with the current date and time.

ABCD
1NameDateStart TimeStop Time
2Bill03/10/201709:1513:43
3Bill03/14/201709:3115:30
4Bill03/17/201709:20
5Bill

<tbody>
</tbody>

I hope this makes sense! Thanks!
 

Excel Facts

Easy bullets in Excel
If you have a numeric keypad, press Alt+7 on numeric keypad to type a bullet in Excel.
Try this:
Start script:
Code:
Sub Enter_Start()
Application.ScreenUpdating = False
Dim i As Long
Dim Lastrow As Long
Lastrow = Cells(Rows.Count, "A").End(xlUp).Row + 1
Cells(Lastrow, 2).Value = Date
Cells(Lastrow, 3).Value = Time
Application.ScreenUpdating = True
End Sub

Stop Script
Code:
Sub Enter_Stop()
Application.ScreenUpdating = False
Dim i As Long
Dim Lastrow As Long
Lastrow = Cells(Rows.Count, "A").End(xlUp).Row + 1
Cells(Lastrow, 4).Value = Time
Application.ScreenUpdating = True
End Sub
 
Upvote 0
Your question seems very clear.

Try this, both macros are here, you just need to assign the shortcut you want to use by going into view -> macros -> options I am not sure if this can be assigned in the Code.

So just create a new macro, copy and paste the code below into the new macro, this will create 2 macros. Then edit each one with the shortcut stated above and then create buttons and assign the macros accordingly.

Code:
Sub Start_Button()

CurStartRow = Cells(Rows.Count, "B").End(xlUp).Row
CurStopRow = Cells(Rows.Count, "D").End(xlUp).Row


If CurStopRow < CurStartRow Then


    Cont = MsgBox("You have not stopped that previous row, are you sure you want to start a new one?", vbYesNo)
    
    If Cont = vbNo Then
    
        Exit Sub
        End If
    Else
    Range("B" & CurStartRow + 1).Value = Date
    Range("C" & CurStartRow + 1).Value = Time




End If
End Sub




Sub Stop_Button()


CurStopRow = Cells(Rows.Count, "D").End(xlUp).Row
CurStartRow = Cells(Rows.Count, "B").End(xlUp).Row


If CurStopRow = CurStartRow Then


    Cont = MsgBox("You have not started a row yet are you sure you want to stop?", vbYesNo)
    
    If Cont = vbNo Then
    
        Exit Sub
        End If
    Else


Range("D" & CurStopRow + 1).Value = Time


End Sub
 
Last edited:
Upvote 0
I think I made a mistake.
Try this:


Start script:
Code:
Sub Enter_Start()
Application.ScreenUpdating = False
Dim i As Long
Dim Lastrow As Long
Lastrow = Cells(Rows.Count, "A").End(xlUp).Row
Cells(Lastrow, 2).Value = Date
Cells(Lastrow, 3).Value = Format(Time, "hh:mm")
Application.ScreenUpdating = True
End Sub


Stop script:

Code:
Sub Enter_Stop()
Application.ScreenUpdating = False
Dim i As Long
Dim Lastrow As Long
Lastrow = Cells(Rows.Count, "A").End(xlUp).Row
Cells(Lastrow, 4).Value = Format(Time, "hh:mm")
Application.ScreenUpdating = True
End Sub
 
Upvote 0
Try this. Format the columns for the date and time formats you want.

Howard

Code:
Sub My_D_T_Start()
 Cells(Rows.Count, "B").End(xlUp)(2) = Date
 Cells(Rows.Count, "C").End(xlUp)(2) = Time
End Sub


Sub My_T_Stop()
 Cells(Rows.Count, "D").End(xlUp)(2) = Time
End Sub
 
Upvote 0
Here is another way, run from one button on the sheet. You make choice for date/time in B & C or stop time in D.
Copy to a standard module. (Not the sheet module.)

Howard


Code:
Option Explicit

Sub my_Date_Time()

Dim myDT

myDT = Application.InputBox(prompt:="For DATE and START Time - enter " & """B""" & vbCr & vbCr & _
                                    "For Stop Time - enter " & """D""", _
                                     Title:="DATE n TIME 'R US", Type:=2)
     
With ActiveSheet
If myDT = " " Then Exit Sub
 
If myDT = "B" Or myDT = "b" Then
 Cells(Rows.Count, "B").End(xlUp)(2) = Date
 Cells(Rows.Count, "C").End(xlUp)(2) = Time

ElseIf myDT = "D" Or myDT = "d" Then
 Cells(Rows.Count, "D").End(xlUp)(2) = Time

 End If
End With
 
End Sub
 
Upvote 0

Forum statistics

Threads
1,214,940
Messages
6,122,352
Members
449,080
Latest member
Armadillos

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