Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 68
Default Excel matching question

I have a cell that looks like this:
=IF(B23=B22,C22,"")

But what I really want is a Match function that finds the last match
between B23 and any row above it, and then copies the value in column
C to C23.

e.g.
B C
19 red 3
20 green 5
21 red 6
22 blue 17


How do I get C23 to enter a 6 when I enter "red" in B23?

Note: This spreadsheet will grow, I add a new row or two every week.
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 812
Default Excel matching question

Here is a user-defined function. You may want to omit the 3rd argument
and use
MatchLast = LookupArray(iRow, 2).

Function MatchLast(LookupValue, LookupArray As Range, Column As
Integer)
Dim c As Range
Dim iRow As Integer
For iRow = LookupArray.Rows.Count To 1 Step -1
If LookupArray(iRow, 1) = LookupValue Then
MatchLast = LookupArray(iRow, Column)
Exit Function
End If
Next iRow
End Function

Hth,
Merjet


  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 68
Default Excel matching question

On 10 May 2007 08:42:05 -0700, merjet wrote:

Here is a user-defined function. You may want to omit the 3rd argument
and use
MatchLast = LookupArray(iRow, 2).



I actually will be populating quite a few cells with values on more
than one tabbed page. I'm not sure whether that's an argument for a
3rd argument.

I saved the macro (it wanted to make it a sub), and haven't quite got
the cell working.
  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 68
Default Excel matching question

On Thu, 10 May 2007 10:00:28 -0600, Howard Brazee
wrote:

I saved the macro (it wanted to make it a sub), and haven't quite got
the cell working.


I get a compile error, expected type name. I suspect I'm not passing
something correctly.
  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 812
Default Excel matching question

I saved the macro (it wanted to make it a sub), and haven't
quite got the cell working.


Post your code. Some cell data would help, too.

Merjet





  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 68
Default Excel matching question

On 10 May 2007 09:12:56 -0700, merjet wrote:

I saved the macro (it wanted to make it a sub), and haven't
quite got the cell working.


Post your code. Some cell data would help, too.

Merjet



I'm not familiar with user created functions, so I didn't want to get
fancy.

My cell's value has:
=MatchLast($B24, $B$2:$B23, 3)

for now, just to see what I would get. I guessed that "column as
integer" meant, translate C to 3.

When I copied in your code, I selected Tools/Macro/Macros, entered in
MatchLast, erased the stub code for a subroutine, and pasted in your
function. That may have been the wrong thing to do, but I looked
all over for how to enter a function. (I found a place for recording
a macro - maybe I should have done that and then edited it down).

I told it that it is a global macro.
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
Another question regarding matching names and adding spaces ILunacy Excel Worksheet Functions 2 February 16th 10 03:20 PM
Matching a Date question ben simpson New Users to Excel 1 March 9th 06 09:12 AM
Matching Question carl Excel Worksheet Functions 0 December 9th 05 08:35 PM
Matching Question carl Excel Worksheet Functions 3 March 1st 05 10:55 PM
vba question.. matching in columns yonnuta Excel Programming 0 January 20th 04 06:04 PM


All times are GMT +1. The time now is 03:38 AM.

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

About Us

"It's about Microsoft Excel"