Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 206
Default Find first and last instance

Hi all,

I have a column containing Month names. Each month is grouped together. IE:
March
March
April
April
April
May
May
May
May
etc etc

how do i find the row of the first instance of a certain month, and also the
row of the last instance of the same month


tia

J
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default Find first and last instance

Sub EFGH()
Dim rng As Range, rng1 As Range
Dim sAddr As String
Set rng = Columns(1).Find("April")
sAddr = rng.Address
If Not rng Is Nothing Then
Do
Set rng1 = rng
Set rng = Columns(1).FindNext(rng)
Loop While rng.Address < sAddr
Range(rng, rng1).Select
End If

End Sub


--
Regards,
Tom Ogilvy


"Gixxer_J_97" wrote in message
...
Hi all,

I have a column containing Month names. Each month is grouped together.

IE:
March
March
April
April
April
May
May
May
May
etc etc

how do i find the row of the first instance of a certain month, and also

the
row of the last instance of the same month


tia

J



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 694
Default Find first and last instance

Hi,
you can use the find function and tell it to search within the whole range
(say rgSrc) as follow:
- for the First occurence: start search after the last cell of the range
rgSrc and search in Direction forward (xlNext)
- for the Last occurence: start search after the first cell of the range
rgSrc and search in Direction backward (xlPrevious)

Sub test()
Dim rgSrc As Range, rgFirst As Range, rgLast As Range

Set rgSrc = Range("A2:A120")

Set rgFirst = rgSrc.Find(what:="March",
after:=rgSrc.Cells(rgSrc.Cells.Count) _
,LookIn:=xlValues, lookat:=xlWhole, searchdirection:=xlNext)
Set rgLast = rgSrc.Find(what:="March", after:=rgSrc.Cells(1), _
LookIn:=xlValues, lookat:=xlWhole, searchdirection:=xlPrevious)
Debug.Print rgFirst.Address, rgLast.Address
End Sub
--
Regards,
Sébastien
<http://www.ondemandanalysis.com


"Gixxer_J_97" wrote:

Hi all,

I have a column containing Month names. Each month is grouped together. IE:
March
March
April
April
April
May
May
May
May
etc etc

how do i find the row of the first instance of a certain month, and also the
row of the last instance of the same month


tia

J

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 206
Default Find first and last instance

Thanks Tom!

J

"Tom Ogilvy" wrote:

Sub EFGH()
Dim rng As Range, rng1 As Range
Dim sAddr As String
Set rng = Columns(1).Find("April")
sAddr = rng.Address
If Not rng Is Nothing Then
Do
Set rng1 = rng
Set rng = Columns(1).FindNext(rng)
Loop While rng.Address < sAddr
Range(rng, rng1).Select
End If

End Sub


--
Regards,
Tom Ogilvy


"Gixxer_J_97" wrote in message
...
Hi all,

I have a column containing Month names. Each month is grouped together.

IE:
March
March
April
April
April
May
May
May
May
etc etc

how do i find the row of the first instance of a certain month, and also

the
row of the last instance of the same month


tia

J




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
Find last instance of character in text KonaAl Excel Discussion (Misc queries) 21 November 28th 06 06:59 PM
How do I find the last instance of data in a column IJ Rosenblum Excel Worksheet Functions 1 February 1st 06 08:28 PM
Find 2nd instance of a word in a range. Grumpy Grandpa Excel Worksheet Functions 8 December 5th 05 03:29 PM
Vlookup to find Second INstance [email protected] Excel Worksheet Functions 1 September 16th 05 03:33 AM
Find nth instance of a character in a string Francis Hayes (The Excel Addict) Excel Discussion (Misc queries) 7 January 21st 05 03:44 PM


All times are GMT +1. The time now is 01:07 AM.

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"