Sub date
Dim DTE as Date
MBox = InputBox(“Enter Friday date”)
If IsDate(MBox) Then
DTE = CDate(MBox)
Range(“F” & Rows.Count).End(xlUp).Offset(1).Select
Selection.Insert Shift:=xlDown
Selection.Insert Shift:=xlDown
Else
MsgBox(“This isn’t a date. Try again.”)
End if
End sub
我需要代码在找到用户在输入框中输入的日期后添加两行,然后将D列中的值相加。我意识到范围行不正确,但是我不确定如何插入行在我输入日期之后。
答案 0 :(得分:1)
几件事
date
,因为这是保留字.Selection
Application.Inputbox
,则可以控制输入类型(在某种程度上 ) 假设您正在Sheet1
上工作,并且要与用户输入范围Column F
匹配的日期
Sub Date_Finder()
Dim ws As Worksheet: Set ws = ThisWorkbook.Sheets("Sheet1") '<-- 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("F:F").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