Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 34
Default Find match from 1st 3 columns and return the row number

I need help writing a function that would find a match in the first 3 columns
in a sheet. Then return the row number where the combination was found. Then
return the row number of the next non blank row it finds. Here is an example:

Row1 ColA ColB ColC
Row2 DDD EEE FFF
Row3
Row4 HHH

I would need to search for the row that contains DDD in ColA, if match then
look for EEE in ColB, and if match then look for FFF in ColC. Once found then
return the row number where found, in this case 2. Then find the next value
in ColA that is non blank and return this row number, in this case 4.

I really appreciate your help with this. God bless you all for all the help
you provide!
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35,218
Default Find match from 1st 3 columns and return the row number

Maybe...

=match(1,(a4:a99=a2)*(b4:b99=b2)*(c4:c99=c2),0)

This is an array formula. Hit ctrl-shift-enter instead of enter. If you do it
correctly, excel will wrap curly brackets {} around your formula. (don't type
them yourself.)

Adjust the range to match--but you can only use the whole column in xl2007.


Will return 1 if the first row of A4:C99 matches (row 4).
Will return 2 if the second row of A4:C99 matches (row 5).

So if you want to see 4 when it matches row 4, add 3 to the formula:

=3+match(1,(a4:a99=a2)*(b4:b99=b2)*(c4:c99=c2),0)
or
=row(a4:a99)-1+match(1,(a4:a99=a2)*(b4:b99=b2)*(c4:c99=c2),0)
(If you want to adjust the ranges)



HelpMe wrote:

I need help writing a function that would find a match in the first 3 columns
in a sheet. Then return the row number where the combination was found. Then
return the row number of the next non blank row it finds. Here is an example:

Row1 ColA ColB ColC
Row2 DDD EEE FFF
Row3
Row4 HHH

I would need to search for the row that contains DDD in ColA, if match then
look for EEE in ColB, and if match then look for FFF in ColC. Once found then
return the row number where found, in this case 2. Then find the next value
in ColA that is non blank and return this row number, in this case 4.

I really appreciate your help with this. God bless you all for all the help
you provide!


--

Dave Peterson
  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 9,101
Default Find match from 1st 3 columns and return the row number

Try this function

Function FindRowAfterMatch() As Long

With ActiveSheet
LastRow = .Range("A" & Rows.Count).End(xlUp).Row
FoundMatch = False
For RowCount = 2 To LastRow
If FoundMatch = False Then
If .Range("A" & RowCount) = "DDD" And _
.Range("B" & RowCount) = "EEE" And _
.Range("C" & RowCount) = "FFF" Then

FoundMatch = True
End If
Else
If .Range("A" & RowCount) < "" Then
FindRowAfterMatch = RowCount
Exit For
End If
End If

Next RowCount

End With

End Function


"HelpMe" wrote:

I need help writing a function that would find a match in the first 3 columns
in a sheet. Then return the row number where the combination was found. Then
return the row number of the next non blank row it finds. Here is an example:

Row1 ColA ColB ColC
Row2 DDD EEE FFF
Row3
Row4 HHH

I would need to search for the row that contains DDD in ColA, if match then
look for EEE in ColB, and if match then look for FFF in ColC. Once found then
return the row number where found, in this case 2. Then find the next value
in ColA that is non blank and return this row number, in this case 4.

I really appreciate your help with this. God bless you all for all the help
you provide!

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 34
Default Find match from 1st 3 columns and return the row number

Thank you! This is very helpful but I have a couple of questions:

1- where is the row number of the match?
2- FindRowAfterMatch is the row number of the next non blank in col A?
3- What happens if combination found is the last row in rowcount, what would
be the value of FindRowAfterMatch?

Thank you very much for your help.

"Joel" wrote:

Try this function

Function FindRowAfterMatch() As Long

With ActiveSheet
LastRow = .Range("A" & Rows.Count).End(xlUp).Row
FoundMatch = False
For RowCount = 2 To LastRow
If FoundMatch = False Then
If .Range("A" & RowCount) = "DDD" And _
.Range("B" & RowCount) = "EEE" And _
.Range("C" & RowCount) = "FFF" Then

FoundMatch = True
End If
Else
If .Range("A" & RowCount) < "" Then
FindRowAfterMatch = RowCount
Exit For
End If
End If

Next RowCount

End With

End Function


"HelpMe" wrote:

I need help writing a function that would find a match in the first 3 columns
in a sheet. Then return the row number where the combination was found. Then
return the row number of the next non blank row it finds. Here is an example:

Row1 ColA ColB ColC
Row2 DDD EEE FFF
Row3
Row4 HHH

I would need to search for the row that contains DDD in ColA, if match then
look for EEE in ColB, and if match then look for FFF in ColC. Once found then
return the row number where found, in this case 2. Then find the next value
in ColA that is non blank and return this row number, in this case 4.

I really appreciate your help with this. God bless you all for all the help
you provide!

  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 34
Default Find match from 1st 3 columns and return the row number

Thanks!

"Dave Peterson" wrote:

Maybe...

=match(1,(a4:a99=a2)*(b4:b99=b2)*(c4:c99=c2),0)

This is an array formula. Hit ctrl-shift-enter instead of enter. If you do it
correctly, excel will wrap curly brackets {} around your formula. (don't type
them yourself.)

Adjust the range to match--but you can only use the whole column in xl2007.


Will return 1 if the first row of A4:C99 matches (row 4).
Will return 2 if the second row of A4:C99 matches (row 5).

So if you want to see 4 when it matches row 4, add 3 to the formula:

=3+match(1,(a4:a99=a2)*(b4:b99=b2)*(c4:c99=c2),0)
or
=row(a4:a99)-1+match(1,(a4:a99=a2)*(b4:b99=b2)*(c4:c99=c2),0)
(If you want to adjust the ranges)



HelpMe wrote:

I need help writing a function that would find a match in the first 3 columns
in a sheet. Then return the row number where the combination was found. Then
return the row number of the next non blank row it finds. Here is an example:

Row1 ColA ColB ColC
Row2 DDD EEE FFF
Row3
Row4 HHH

I would need to search for the row that contains DDD in ColA, if match then
look for EEE in ColB, and if match then look for FFF in ColC. Once found then
return the row number where found, in this case 2. Then find the next value
in ColA that is non blank and return this row number, in this case 4.

I really appreciate your help with this. God bless you all for all the help
you provide!


--

Dave Peterson



  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 9,101
Default Find match from 1st 3 columns and return the row number

The row number gets put into the return parameter of the function

FindRowAfterMatch = RowCount

Nothing will get returned if a match isn't found or the match is in the last
row. In that case FindRowAfterMatch will be null.

If you want something to be returned then the modification below wil return
-1 if nothing is found


Function FindRowAfterMatch() As Long

FindRowAfterMatch = -1

With ActiveSheet
LastRow = .Range("A" & Rows.Count).End(xlUp).Row
FoundMatch = False
For RowCount = 2 To LastRow
If FoundMatch = False Then
If .Range("A" & RowCount) = "DDD" And _
.Range("B" & RowCount) = "EEE" And _
.Range("C" & RowCount) = "FFF" Then

FoundMatch = True
End If
Else
If .Range("A" & RowCount) < "" Then
FindRowAfterMatch = RowCount
Exit For
End If
End If

Next RowCount

End With

End Function






"HelpMe" wrote:

Thank you! This is very helpful but I have a couple of questions:

1- where is the row number of the match?
2- FindRowAfterMatch is the row number of the next non blank in col A?
3- What happens if combination found is the last row in rowcount, what would
be the value of FindRowAfterMatch?

Thank you very much for your help.

"Joel" wrote:

Try this function

Function FindRowAfterMatch() As Long

With ActiveSheet
LastRow = .Range("A" & Rows.Count).End(xlUp).Row
FoundMatch = False
For RowCount = 2 To LastRow
If FoundMatch = False Then
If .Range("A" & RowCount) = "DDD" And _
.Range("B" & RowCount) = "EEE" And _
.Range("C" & RowCount) = "FFF" Then

FoundMatch = True
End If
Else
If .Range("A" & RowCount) < "" Then
FindRowAfterMatch = RowCount
Exit For
End If
End If

Next RowCount

End With

End Function


"HelpMe" wrote:

I need help writing a function that would find a match in the first 3 columns
in a sheet. Then return the row number where the combination was found. Then
return the row number of the next non blank row it finds. Here is an example:

Row1 ColA ColB ColC
Row2 DDD EEE FFF
Row3
Row4 HHH

I would need to search for the row that contains DDD in ColA, if match then
look for EEE in ColB, and if match then look for FFF in ColC. Once found then
return the row number where found, in this case 2. Then find the next value
in ColA that is non blank and return this row number, in this case 4.

I really appreciate your help with this. God bless you all for all the help
you provide!

  #7   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 34
Default Find match from 1st 3 columns and return the row number

Thanks! I modified it a bit to also get the Match Row Number . You are awesome.

"Joel" wrote:

The row number gets put into the return parameter of the function

FindRowAfterMatch = RowCount

Nothing will get returned if a match isn't found or the match is in the last
row. In that case FindRowAfterMatch will be null.

If you want something to be returned then the modification below wil return
-1 if nothing is found


Function FindRowAfterMatch() As Long

FindRowAfterMatch = -1

With ActiveSheet
LastRow = .Range("A" & Rows.Count).End(xlUp).Row
FoundMatch = False
For RowCount = 2 To LastRow
If FoundMatch = False Then
If .Range("A" & RowCount) = "DDD" And _
.Range("B" & RowCount) = "EEE" And _
.Range("C" & RowCount) = "FFF" Then

FoundMatch = True
End If
Else
If .Range("A" & RowCount) < "" Then
FindRowAfterMatch = RowCount
Exit For
End If
End If

Next RowCount

End With

End Function






"HelpMe" wrote:

Thank you! This is very helpful but I have a couple of questions:

1- where is the row number of the match?
2- FindRowAfterMatch is the row number of the next non blank in col A?
3- What happens if combination found is the last row in rowcount, what would
be the value of FindRowAfterMatch?

Thank you very much for your help.

"Joel" wrote:

Try this function

Function FindRowAfterMatch() As Long

With ActiveSheet
LastRow = .Range("A" & Rows.Count).End(xlUp).Row
FoundMatch = False
For RowCount = 2 To LastRow
If FoundMatch = False Then
If .Range("A" & RowCount) = "DDD" And _
.Range("B" & RowCount) = "EEE" And _
.Range("C" & RowCount) = "FFF" Then

FoundMatch = True
End If
Else
If .Range("A" & RowCount) < "" Then
FindRowAfterMatch = RowCount
Exit For
End If
End If

Next RowCount

End With

End Function


"HelpMe" wrote:

I need help writing a function that would find a match in the first 3 columns
in a sheet. Then return the row number where the combination was found. Then
return the row number of the next non blank row it finds. Here is an example:

Row1 ColA ColB ColC
Row2 DDD EEE FFF
Row3
Row4 HHH

I would need to search for the row that contains DDD in ColA, if match then
look for EEE in ColB, and if match then look for FFF in ColC. Once found then
return the row number where found, in this case 2. Then find the next value
in ColA that is non blank and return this row number, in this case 4.

I really appreciate your help with this. God bless you all for all the help
you provide!

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
return proper match from three columns plus766 Excel Worksheet Functions 2 October 2nd 11 07:34 PM
Match 2 Columns, Return 3rd, Differing Match Types Matt.Russett Excel Worksheet Functions 3 May 11th 10 10:45 AM
Match Columns and return value CB Excel Programming 2 December 12th 08 05:20 PM
match 2 columns and return value of another Haz Excel Worksheet Functions 1 July 8th 08 01:46 PM
Find closest match and return next highest number in range x6v87qe Excel Discussion (Misc queries) 4 June 18th 08 01:58 PM


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