Thread: [Solved] Find Date Month
View Single Post
 
Old 07-23-2018, 04:21 PM
macropod's Avatar
macropod macropod is offline Windows 7 64bit Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 22,467
macropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond repute
Default

Quote:
Originally Posted by charlesdh View Post
Would still like see what I did wrong with the code that I have in the file
Well, you said you were looking for just the month, but strdate is only ever defined as a date in the format "mmm-yyyy". Naturally, that looks for the month and year, and will only find them if separated by a '-'. Furthermore, your Find expression looks at the formulae, not the displayed strings and requires a whole-of-cell match instead of a partial match. Try using something along the lines of:
Code:
Sub FindDate()
Dim strdate As String, rCell As Range, lReply As Long
strdate = Format(Sheets("Sheet2").Cells(2, 4).Text, "mmm")
Set rCell = Sheets("Sheet1").Cells.Find(What:=strdate, LookIn:=xlValues, LookAt:=xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext, MatchCase:=False)
If Not rCell Is Nothing Then MsgBox rCell.Address
End Sub
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote