Timesheet add a row based on inputbox entry

cbye

New Member
Joined
Feb 2, 2022
Messages
23
Office Version
  1. 365
Platform
  1. Windows
Hi, I have a timesheet that I need to be able to add a row if the employee worked a double shift. The VBA code that I found seems to be what I need but when I input the date I get "Input not found in range" message. Im not sure what Im missing.

Sub Date_Finder()

Dim ws As Worksheet: Set ws = ThisWorkbook.ActiveSheet '<-- Update
Dim xInput As Date, Found As Range

xInput = Application.InputBox("Enter Date [mm/dd/yyyy]", Type:=1)

If IsDate(xInput) Then
Set Found = ws.Range("B:B").Find(xInput)

If Found Is Nothing Then
MsgBox "Input not found in range"
Else
Found.Offset(1).EntireRow.Insert (xlShiftDown)
Found.Offset(1).EntireRow.Insert (xlShiftDown)
End If
Else
MsgBox "Invalid Entry. Ending sub" & vbNewLine & "Entry: " & xInput, vbCritical
End If

End Sub



Cell Formulas
RangeFormula
E9:E38E9=IF(I9>$F$6,$F$6,I9)
F9:F38F9=MOD((D9-C9),1)*24
B9B9=F4
B10:B38B10=B9+1
E40E40=SUM(E9:E39)
F40,F42F40=SUM(E40:E40)
E42E42=E41*E40
F44F44=F40
F47F47=F42
Cells with Conditional Formatting
CellConditionCell FormatStop If True
C9:C30,C33:C39Cellcontains a blank value textNO
C9:C30,C33:C39Cell Value>"24:00:00"textNO
 
Try adding this
VBA Code:
Found.Offset(1).Resize(1).EntireRow.Insert (xlShiftDown)
Found.Offset(1).Value = xInput     '<--------------added line
Thanks that works. I appreciate your help. And I learned a bit more.
 
Upvote 0

Excel Facts

When did Power Query debut in Excel?
Although it was an add-in in Excel 2010 & Excel 2013, Power Query became a part of Excel in 2016, in Data, Get & Transform Data.

Forum statistics

Threads
1,223,893
Messages
6,175,248
Members
452,623
Latest member
cliftonhandyman

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