Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 22
Default Method to get dates based on Month

Is there any way to have a for/next loop to search a Column for
months? One specific column has inventory number information as well
as date separators, the dates are in "mmm-yy" format.

Sub FindDate()
Dim FoundCell As Range
Dim Mnth As Variant

Range("InvNum").Select

Mnth = ?
For Mnth = Jan To Dec
With Sheets("Job Sheet")
Set FoundCell = .Cells.Find(What:=Mnth, _
After:=.Range("C2"),
LookIn:=xlValues, _
LookAt:=xlPart, SearchOrder: _
=xlByRows,
SearchDirection:=xlNext, _
MatchCase:=False)
If Not FoundCell Is Nothing Then
.Activate
FoundCell.Select
End If
End With
Next Mnth

End Sub

This is just testing code, I have many other actions waiting in anther
routine I need to plug in after this gets done.

Thanks for any help,

Chad

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,939
Default Method to get dates based on Month

Something like this should do it...

Public Sub FindMonths()
Dim rngFound As Range
Dim rngFoundAll As Range
Dim strMonth As String
Dim lngCounter As Long
Dim rngToSearch As Range

Set rngToSearch = Sheets("Job Sheet").Cells

For lngCounter = 1 To 12
strMonth = Format(DateSerial(2007, lngCounter, 1), "Mmm")
Set rngFound = FindOneMonth(strMonth, rngToSearch)
If Not rngFound Is Nothing Then
If rngFoundAll Is Nothing Then
Set rngFoundAll = rngFound
Else
Set rngFoundAll = Union(rngFound, rngFoundAll)
End If
End If
Next lngCounter
If Not rngFoundAll Is Nothing Then rngFoundAll.Select
End Sub

Private Function FindOneMonth(ByVal strMonth As String, _
ByRef rngToSearch As Range) As Range
Dim rngFound As Range
Dim rngFoundAll As Range
Dim strFirstAddress As String

Set FindOneMonth = Nothing
Set rngFound = rngToSearch.Find(What:=strMonth, _
LookIn:=xlValues, _
LookAt:=xlPart, _
MatchCase:=False)
If Not rngFound Is Nothing Then
Set rngFoundAll = rngFound
strFirstAddress = rngFound.Address
Do
Set rngFoundAll = Union(rngFound, rngFoundAll)
Set rngFound = rngToSearch.FindNext(rngFound)
Loop Until rngFound.Address = strFirstAddress
Set FindOneMonth = rngFoundAll
End If
End Function
--
HTH...

Jim Thomlinson


" wrote:

Is there any way to have a for/next loop to search a Column for
months? One specific column has inventory number information as well
as date separators, the dates are in "mmm-yy" format.

Sub FindDate()
Dim FoundCell As Range
Dim Mnth As Variant

Range("InvNum").Select

Mnth = ?
For Mnth = Jan To Dec
With Sheets("Job Sheet")
Set FoundCell = .Cells.Find(What:=Mnth, _
After:=.Range("C2"),
LookIn:=xlValues, _
LookAt:=xlPart, SearchOrder: _
=xlByRows,
SearchDirection:=xlNext, _
MatchCase:=False)
If Not FoundCell Is Nothing Then
.Activate
FoundCell.Select
End If
End With
Next Mnth

End Sub

This is just testing code, I have many other actions waiting in anther
routine I need to plug in after this gets done.

Thanks for any help,

Chad


  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 22
Default Method to get dates based on Month

On Feb 20, 12:17 pm, Jim Thomlinson <James_Thomlin...@owfg-Re-Move-
This-.com wrote:
Something like this should do it...

Than a ton Jim, your code worked perfectly

Chad

Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Calculate Revenue based on dates within a month Annie Excel Worksheet Functions 4 July 29th 09 10:05 PM
Return dates based on month and day of week lesg46 Excel Worksheet Functions 8 January 4th 07 12:47 AM
Dates - Several Days In a month to month only Andy_Pimp Excel Discussion (Misc queries) 1 February 28th 06 11:11 AM
Fill column with dates of month depending on month in A1 [email protected] Excel Programming 7 March 11th 05 12:41 AM
How can i filter dates based on day of month Saurabh Excel Worksheet Functions 1 December 12th 04 05:36 PM


All times are GMT +1. The time now is 08:03 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"