Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
?
Solved

Small vlookup issue

Posted on 2011-05-02
6
Medium Priority
?
293 Views
Last Modified: 2012-05-11
Hello all,

I have a small problem with a VLookup macro.


I want to put the result for that formula in column N of active cell.
=VLookup(S2135,'Rate Group'!K:L,2,0)

But it leaves the cell empty all the time.

Here is the macro in my


Private Sub Worksheet_Change(ByVal Target As Range)

Dim QW As Range
Set QW = Intersect(Target, Range("S6:S" & Rows.Count))
If Not QW Is Nothing Then
  If QW.Value > "" Then
    QW.Offset(, -5).Formula = "=IF(ISNA(VLOOKUP(QW.Value,'Rate Group'!K:L,1,0))"

  End If
  QW.Offset(, -5).Value = ""
End If

Open in new window


Can you please help me?

Thanks

0
Comment
Question by:Wilder1626
6 Comments
 
LVL 15

Expert Comment

by:CSLARSEN
ID: 35504540
Private Sub Worksheet_Change(ByVal Target As Range)

Dim QW As Range
Set QW = Intersect(Target, Range("S6:S" & Rows.Count))
If Not QW Is Nothing Then
  If QW.Value > "" Then
    QW.Offset(, -5).Formula = "=IF(ISNA(VLOOKUP(QW.Value,'Rate Group'!K:L,1,0))"

  End If
'WHAT HAPPENS IF YOU REMOVE THIS LINE?  QW.Offset(, -5).Value = ""
End If
cheers
cslarsen
0
 
LVL 11

Author Comment

by:Wilder1626
ID: 35504650
Hello

I have an error in the formula.

Here is the excel spreadsheet has an example.

Thanks again.
DC-Province.xlsm
0
 
LVL 93

Accepted Solution

by:
Patrick Matthews earned 1600 total points
ID: 35504939
Assuming you want to return the name of the province if found, N/A if there is no entry for the code supplied, or a blank if the code column is blank...

Private Sub Worksheet_Change(ByVal Target As Range)
    
    Dim QW As Range, cel As Range
    
    Set QW = Intersect(Target, Range("S6:S" & Rows.Count), Me.UsedRange)
    If Not QW Is Nothing Then
        For Each cel In QW.Cells
            If cel <> "" Then
                cel.Offset(, -5).Formula = "=IFERROR(VLOOKUP(""" & cel & """,'Rate Group'!K:L,2,0),""N/A"")"
            Else
                cel.Offset(, -5).ClearContents
            End If
        Next
    End If
    
End Sub

Open in new window

0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 19

Assisted Solution

by:Arno Koster
Arno Koster earned 400 total points
ID: 35504964
There are a number of issues :

- 3 opening brackets '(' are used, while only 2 closing brackets ')' are in the formula.
the structure should be like
IF(ISNA(VLOOKUP([arguments])), 'then' value, 'else' value)

- you are referring to QW.Value in the formula, which exists only in VBA code, not in excel.
There are 2 choices : using the value of the changed cell in the formula : [...]Vlookup(" & QW.Value & "[...]
or using the cell itself : [...]vlookup(" & QW.address & "[...]

- the vlookup function requires a third argument being the column of the data set which is to be returned for a match (eg. 1 for K or 2 for L)
the structure should be like
VLOOKUP(value, dataset, resulting_column)

0
 
LVL 11

Author Comment

by:Wilder1626
ID: 35505476
Ok, let me test this and i will let you all know the result.

Thanks again
0
 
LVL 11

Author Closing Comment

by:Wilder1626
ID: 35511974
Thanks for your help.

It works perfectly.

Have a great day
0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

You need to know the location of the Office templates folder, so that when you create new templates, they are saved to that location, and thus are available for selection when creating new documents.  The steps to find the Templates folder path are …
Windows Explorer let you handle zip folders nearly as any other folder: Copy, move, change, and delete, etc. In VBA you can also handle normal files and folders, but zip folders takes a little more - and that you'll find here.
This Micro Tutorial will demonstrate how to use a scrolling table in Microsoft Excel using the INDEX function.
Many functions in Excel can make decisions. The most simple of these is the IF function: it returns a value depending on whether a condition you describe is true or false. Once you get the hang of using the IF function, you will find it easier to us…

580 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question