Input username and date vba stamp help

Mykiej23

New Member
Joined
Jun 2, 2016
Messages
22
Hi,

I have got a spreadsheet which has our daily figures into. This has been working ok in an older spreadsheet but we need to recreate the spreadsheet in Office 365 due to compatibility issues.

I've recreated the spreadsheet in the same format however I'm getting an error when I input this formula. It inputs our username and date/time stamp at the end of the row each day to confirm sign off.

Code:
Sub ConfirmEnter()

    Application.ScreenUpdating = False
    Application.DisplayAlerts = False
    
    Range("A1").Formula = "=TODAY()-1"
    UseDate = Range("A1").Value
    Range("A1").ClearContents
        
    Response = MsgBox("Confirm entry for - " & UseDate, vbYesNoCancel + vbQuestion, "Confirm Entry")
        
    If Response = 2 Then
    
        End
    
    ElseIf Response = 7 Then
    
        NewDate = InputBox("Enter date to confirm entry for...(dd/mm/yy)", "Custom Date")
            
            If IsDate(NewDate) = False Then
                Do Until IsDate(NewDate) = True
                    NewDate = InputBox("The date you entered has not been recognised - please try again.....or enter 'abort' to quit.", "Try Again")
                        If UCase(NewDate) = "ABORT" Then End
                Loop
            End If
        
        UseDate = CDate(NewDate)
    
    End If
            
        Call CheckDateForExistingEntry(UseDate)
    
    Sheets("Summary").Unprotect Password:="4010"
    RangeDateRow = Application.Match(CLng(UseDate), Range("A1:A50000"), 0)
    LastColumn = Range("IV6").End(xlToLeft).Column
    UserId = Environ("UserName")
    
    Cells(RangeDateRow, LastColumn - 6).Formula = UserId
    Cells(RangeDateRow, LastColumn - 5).Formula = "=NOW()"
    Cells(RangeDateRow, LastColumn - 5).Copy
    Cells(RangeDateRow, LastColumn - 5).PasteSpecial xlPasteValues
        
    Range("B7").Select
    Application.CutCopyMode = False
    Sheets("Summary").Protect Password:="4010"
    
End Sub

I either get stopped at Call CheckDateForExistingEntry(UseDate) or if I remove this line out it stops at Range("A1").Formula = "=TODAY()-1" unless I have =today()-1 already in cell A1.

Can anyone offer me their wisdom on this? Any help would be appreciated :)
 
Last edited by a moderator:

Excel Facts

Excel motto
Not everything I do at work revolves around Excel. Only the fun parts.
Hi,

I either get stopped at Call CheckDateForExistingEntry(UseDate)

If created a new workbook did you copy this procedure as well?


Just a guess but see if this update to your code will do what you want


Code:
Sub ConfirmEnter()
    Dim UserID As String
    Dim Response As VbMsgBoxResult
    Dim ConfirmDate As Variant, RangeDateRow As Variant
    Dim UseDate As Date
    Dim LastColumn As Long
    Dim wsSummary As Worksheet
    
    UserID = Environ("UserName")
    
    UseDate = Date - 1
    
    Set wsSummary = Worksheets("Summary")
    
    Do
        ConfirmDate = InputBox(UserID & Chr(10) & "Confirm entry for date shown or" & Chr(10) & _
        "Enter Custom date to confirm entry", "Custom Date", UseDate)
'cancel pressed
        If StrPtr(ConfirmDate) = 0 Then Exit Sub
        
        If Not IsDate(ConfirmDate) Then
'invalid date entry
            Response = MsgBox("The date you entered has not been recognised", 53, "Try Again")
            If Response = vbCancel Then Exit Sub
            
        Else
            UseDate = DateValue(ConfirmDate)
            RangeDateRow = Application.Match(CLng(UseDate), wsSummary.Columns(1), 0)
'if match not found inform user
            If IsError(RangeDateRow) Then
                Response = MsgBox(ConfirmDate & Chr(10) & "Date Not Found", 53, "Not Found")
                If Response = vbCancel Then Exit Sub
            Else
'date found
                Exit Do
            End If
        End If
        
    Loop
    
'update record
    With wsSummary
        .Unprotect Password:="4010"
        
        LastColumn = .Range("IV6").End(xlToLeft).Column
        
        .Cells(RangeDateRow, LastColumn - 6).Value = UserID
        .Cells(RangeDateRow, LastColumn - 5).Value = Now()
        
        .Protect Password:="4010"
    End With
    
End Sub

Dave
 
Upvote 0

Forum statistics

Threads
1,223,099
Messages
6,170,107
Members
452,302
Latest member
TaMere

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