Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 8
Default Find first and/or last cell that matches data

I have a spreadsheet like this:
A B C D
1 ID Loc Date Rep
2 25 a4 4/6/05 Dave
3 28 a5 4/6/05 Dave
4 32 a7 4/6/05 Dave
5 76 a4 4/6/05 Fred
6 84 a5 4/6/05 Fred
7 66 a7 4/6/05 Fred
8 54 a3 4/6/05 Jack
9 22 a3 4/6/05 Jack

I want to locate the address of the cell in column A on the row containing
the FIRST appearance of "Fred" (A5 in this case) and also the address of the
cell containing the LAST appearance of "Fred" (D7 in this case). I want to
use these values in a range reference so I can sort different sections of the
spread sheet in different orders.
Thanks!
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,441
Default Find first and/or last cell that matches data

Molasses,

The block of 3 rows by 4 columns of cells with Fred in column D can be found
by:

Dim myCell As Range
Set myCell = Range("D:D").Find("Fred")
MsgBox Range(myCell, Cells(myCell.Row + _
Application.CountIf(Range("D:D"), "Fred") - 1, 1)).Address

Note that this requires the column D be sorted.

HTH,
Bernie
MS Excel MVP


"Molasses26" wrote in message
...
I have a spreadsheet like this:
A B C D
1 ID Loc Date Rep
2 25 a4 4/6/05 Dave
3 28 a5 4/6/05 Dave
4 32 a7 4/6/05 Dave
5 76 a4 4/6/05 Fred
6 84 a5 4/6/05 Fred
7 66 a7 4/6/05 Fred
8 54 a3 4/6/05 Jack
9 22 a3 4/6/05 Jack

I want to locate the address of the cell in column A on the row containing
the FIRST appearance of "Fred" (A5 in this case) and also the address of
the
cell containing the LAST appearance of "Fred" (D7 in this case). I want
to
use these values in a range reference so I can sort different sections of
the
spread sheet in different orders.
Thanks!



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 8
Default Find first and/or last cell that matches data

Fantastic!! It works perfectly - Thanks!!!

"Bernie Deitrick" wrote:

Molasses,

The block of 3 rows by 4 columns of cells with Fred in column D can be found
by:

Dim myCell As Range
Set myCell = Range("D:D").Find("Fred")
MsgBox Range(myCell, Cells(myCell.Row + _
Application.CountIf(Range("D:D"), "Fred") - 1, 1)).Address

Note that this requires the column D be sorted.

HTH,
Bernie
MS Excel MVP


"Molasses26" wrote in message
...
I have a spreadsheet like this:
A B C D
1 ID Loc Date Rep
2 25 a4 4/6/05 Dave
3 28 a5 4/6/05 Dave
4 32 a7 4/6/05 Dave
5 76 a4 4/6/05 Fred
6 84 a5 4/6/05 Fred
7 66 a7 4/6/05 Fred
8 54 a3 4/6/05 Jack
9 22 a3 4/6/05 Jack

I want to locate the address of the cell in column A on the row containing
the FIRST appearance of "Fred" (A5 in this case) and also the address of
the
cell containing the LAST appearance of "Fred" (D7 in this case). I want
to
use these values in a range reference so I can sort different sections of
the
spread sheet in different orders.
Thanks!




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
Maddening Dilemma - Compare each cell within column a to each cell in column b and find unique matches [email protected] Excel Worksheet Functions 66 May 1st 23 03:44 AM
Apply Conditional Formatting If Data in More Than 1 Cell Matches Maureen Excel Discussion (Misc queries) 5 March 5th 09 03:35 PM
how do i find multiple matches of one data item in an excel range DivaHouston Excel Discussion (Misc queries) 1 January 7th 08 02:43 PM
Find Data from one sheet that matches Brian Shafer Excel Discussion (Misc queries) 1 October 19th 07 06:58 PM
how to find all matches in an array Greg Excel Discussion (Misc queries) 2 August 31st 05 09:04 PM


All times are GMT +1. The time now is 12:21 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"