我有一个表格,我想在其中插入一个日期,如图所示。它会将日期复制到某个连续范围。程序必须找到范围,然后使用输入框插入日期。我使用了下面的代码。问题是它没有选择表格内的范围。如何解决这个问题。帮我
Sub FillFirstDay()
Dim ws As Worksheet
Dim rng As Range
Dim LastRow As Long
Dim table As ListObject
Dim dat As Date
Set ws = Sheets("Raw Data")
dat = Application.InputBox(prompt:="Enter the received date of the current Month", Title:="Date", Default:=Format(Date, "dd/mm/yyyy"), Type:=2)
If dat = False Then
MsgBox "Enter a Date", , "Date"
Exit Sub
End If
With ws
LastRow = .Range("A" & .Rows.Count).End(xlUp).Row
firstRow = .Range("C" & .Rows.Count).End(xlUp).Row + 1
Set rng = Range(.Range("C" & firstRow), .Range("C" & LastRow))
End With
If firstRow >= LastRow Then Exit Sub
With rng
.Value = dat
.NumberFormat = "m/d/yyyy"
.NumberFormat = "[$-409]dd-mmm-yy;@"
End With
End Sub