Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > Microsoft Office > Excel VBA > Excel VBA
Password Reminder
Register
| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
Excel VBA Discuss using VBA for Excel programming.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Excel VBA section of the Wrox Programmer to Programmer discussions. This is a community of tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old August 2nd, 2006, 06:54 PM
Authorized User
 
Join Date: Jul 2006
Location: Kalamazoo, MI, USA.
Posts: 27
Thanks: 0
Thanked 0 Times in 0 Posts
Default Excel/VBA Multi-Column Lookup - Round 2

Since my earlier post has gone in a different direction, I have created a very simple test of what I am trying to do. The worksheet with the VB function is attached. Can someone please tell me what I am doing wrong? Thanks for all the help you all are giving me. I'm just not getting it.

I don't seem to be able to attach a file, so here is the sheet I have made:
The 4th/10th column contains Rater(Chart,A1,B1,C1) Rater(Chart2,G1,H1,I1)
Subsequent rows have the different row number.

    Test 1 - Range Below Test 2 - Range Below
A C E #VALUE! 1 2 3 #VALUE!
A C F #VALUE! 2 3 1 #VALUE!
A C G #VALUE! 3 1 2 #VALUE!
A C H #VALUE! 4 5 6 #VALUE!
A C I #VALUE! 5 4 6 #VALUE!
B D J #VALUE! 6 5 4 #VALUE!
B D K #VALUE! 7 8 9 #VALUE!
B D L #VALUE! 8 9 7 #VALUE!
B D M #VALUE! 9 7 8 #VALUE!
B D N #VALUE! 10 9 8 #VALUE!



This test attempts to lookup text values. This test attempts to lookup numeric values.
Cells are formatted "General" since Cells are formatted "General" since
Function uses Variant. Function uses Variant.






Range is Chart Range is Chart2

10 10
CUST PICKUP DROP RATE CUST PICKUP DROP RATE
A C E 1 1 2 3 1
A C F 2 2 3 1 2
A C G 3 3 1 2 3
A C H 4 4 5 6 4
A C I 5 5 4 6 5
B D J 6 6 5 4 6
B D K 7 7 8 9 7
B D L 8 8 9 7 8
B D M 9 9 7 8 9
B D N 10 10 9 8 10


Here is the VB Function I am using:

Code:
Public Function Rater(CRates, x As Variant, y As Variant, z As Variant)
    Dim a As Integer
    Dim last As Integer
    Rater = 0
        last = Worksheets("sheet1").Range(CRates).Cells(1, 1).Value
        For a = 3 To last
            If (x = Worksheets("sheet1").Range(CRates).Cells(a, 1).Value) Then
                If (y = Worksheets("sheet1").Range(CRates).Cells(a, 2).Value) Then
                    If (z = Worksheets("sheet1").Range(CRates).Cells(a, 3).Value) Then
                        Rater = Worksheets("sheet1").Range(CRates).Cells(a, 4).Value
                        Exit Function
                    End If
                End If
            End If
        Next a
End Function
:)
Reply With Quote
  #2 (permalink)  
Old August 3rd, 2006, 03:41 AM
Authorized User
 
Join Date: Jul 2006
Location: , , Poland.
Posts: 23
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Hi,

In your test change Rater(Chart,A1,B1,C1) on this =Rater("Chart";A1;B1;C1) and Rater(Chart2,G1,H1,I1) on this =Rater("Chart2";A1;B1;C1)

Reply With Quote
  #3 (permalink)  
Old August 3rd, 2006, 07:56 AM
Authorized User
 
Join Date: Jul 2006
Location: Kalamazoo, MI, USA.
Posts: 27
Thanks: 0
Thanked 0 Times in 0 Posts
Default

At last!! Thanks so much for your help. Everything works the way I wanted it to.

Thanks again for all the help.

Terry
Reply With Quote
  #4 (permalink)  
Old August 3rd, 2006, 05:30 PM
Authorized User
 
Join Date: Jul 2006
Location: , , Poland.
Posts: 23
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Hi,
I am glad that I could help You.
I see that you used my answer from your earlier topic (Multi-Column Array Search)- replecement "Return" on Exit Function". Could You confirm it in that topic?
BR
Kazik

Reply With Quote
  #5 (permalink)  
Old August 3rd, 2006, 07:28 PM
Authorized User
 
Join Date: Jul 2006
Location: Kalamazoo, MI, USA.
Posts: 27
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Hi Kazik,

You were right on changing the Return to Exit Function. Everything works just the way I want it now. Thanks again for your help.

Terry
Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

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


Similar Threads
Thread Thread Starter Forum Replies Last Post
Round Function in Derived column transformation loveyaseen BOOK: Professional SQL Server 2005 Integration Services ISBN: 0-7645-8435-9 0 October 31st, 2007 08:19 AM
Excel Automation fails second time round feets Excel VBA 2 October 31st, 2007 07:48 AM
DTS - Multiple Column Lookup Problem asimahmed SQL Server DTS 2 April 4th, 2006 01:58 PM
multi-column combo myth12345 VB How-To 1 January 3rd, 2005 04:29 PM
add column in excel with VBA exarkuun Excel VBA 2 November 19th, 2003 09:37 AM



All times are GMT -4. The time now is 12:19 AM.


Powered by vBulletin®
Copyright ©2000 - 2019, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.