data on my Excel sheet我想在列A中查找日期。這是日期格式:「yyyy/mm/dd hh:mm:ss」。它總是發現什麼,但我正在尋找的日期是在A列 這是我的代碼片段:在列中查找日期值VBA
Dim LastDay As Date
Dim strdate As String
Dim rCell As Range
strdate = Format(LastDay, "yyyy/mm/dd hh:mm:ss")
Set rCell = Cells.Find(What:=CDate(strdate), After:=Range("A1"), LookIn:=xlValues _
, LookAt:=xlWhole, SearchOrder:=xlByRows, SearchDirection:=xlNext, MatchCase:=False)
If rCell Is Nothing Then
MsgBox ("nothing")
Else
編輯:每個評論的新代碼。
Sub Copy()
Dim LastDayRow As Long
Dim FirstDayRow As Long
Dim LastDay As Date
Dim FirstDay As Date
Dim rcell As Range
LastDayRow = Range("E" & Rows.Count).End(xlUp).Row
Range("E" & LastDayRow).Copy Range("G1")
FirstDayRow = Range("A" & Rows.Count).End(xlUp).Row
Range("A" & FirstDayRow).Copy Range("G2")
LastDay = Cells(LastDayRow, "E").Value
FirstDay = Cells(FirstDayRow, "A").Value
Set rcell = Cells.Find(What:=LastDay, After:=Range("A1"), LookIn:=xlFormulas _
, LookAt:=xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext)
If rcell Is Nothing Then
MsgBox ("nothing")
End If
End Sub
從您提供的代碼,它不會出現你設置你的'LastDay'變量的任何值。 – Carrosive
您編寫的代碼是基於xlValue查找的。單元格中的日期存儲實際上只是數字。因此,您將無法使用LookIn查找它:= xlValue –
也可能是格式(將日期轉換爲字符串格式;並且您正在查找日期 – User632716