Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Microsoft Office > Excel VBA > Excel VBA
|
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 software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old August 2nd, 2006, 06:54 PM
Authorized User
 
Join Date: Jul 2006
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
:)
 
Old August 3rd, 2006, 03:41 AM
Authorized User
 
Join Date: Jul 2006
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)

 
Old August 3rd, 2006, 07:56 AM
Authorized User
 
Join Date: Jul 2006
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
 
Old August 3rd, 2006, 05:30 PM
Authorized User
 
Join Date: Jul 2006
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

 
Old August 3rd, 2006, 07:28 PM
Authorized User
 
Join Date: Jul 2006
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





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





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.