Solved

Vlookup not Inserting Correctly

Posted on 2014-01-29
3
193 Views
Last Modified: 2014-02-03
I having problems with this formula.  It does not enter correctly in C3.  I either does not copy down to the next row correctly or it adds B2 reference not B3.  

Sheet1.Range("C3:C" & Lastrow).FormulaR1C1 = "=(VLOOKUP(B3,'Vendor'!$E$2:G9,2,FALSE))"
_____________________________________________________________

Sub InsertVS()
    Dim Lastrow As Long

    Application.ScreenUpdating = False
   

    Sheet27.Range("C:D").EntireColumn.Insert
     
    Lastrow = Sheet27.Cells(Sheet27.Rows.Count, "B").End(xlUp).Row
 Sheet27.Range("C3").Select
    Sheet27.Range("C3:C" & Lastrow).FormulaR1C1 = "=(VLOOKUP(B3,'Vendor'!$E$2:G497,2,FALSE))"
     
    Sheet27.Range("D3:D" & Lastrow).FormulaR1C1 = "=VLOOKUP(B3,'Vendor'!$E$2:H497,3,FALSE)"
 
 
 Sheet27.Columns("C:D").Select
        Selection.Replace What:="=", Replacement:="=", LookAt:=xlPart, _
        SearchOrder:=xlByRows, MatchCase:=False, SearchFormat:=False, _
        ReplaceFormat:=False
       
   
       
    Application.ScreenUpdating = True
   
 
 
End Sub
vlookup.zip
0
Comment
Question by:leezac
3 Comments
 
LVL 22

Expert Comment

by:Dreamboat
ID: 39819431
Sheet1.Range("C3:C" & Lastrow).Formula = "=(VLOOKUP(B3,Vendor!$E$2:$G$9,2,FALSE))"
   
    Sheet1.Range("D3:D" & Lastrow).Formula = "=VLOOKUP(B3,Vendor!$E$2:$H$9,3,FALSE)"
 

(Remove "R1C1" and put $ on your entire lookup range. Not sure which one did it, prolly R1C1)
0
 

Author Comment

by:leezac
ID: 39819454
Ok - I changed, but put B3 in C3 and C4.  Need for it to copy down B3, B4 B5 etc.
0
 
LVL 32

Accepted Solution

by:
Rob Henson earned 500 total points
ID: 39820308
In your script you are effectively telling the formula to be string of text which Excel then recognises as a formula. If you rewrite the formula to R1C1 notation, even as a string of text excel will then evaluate correctly.

Formula for C3 would be:

=VLOOKUP(RC[-1],Vendor!R2C5:R9C7,2,FALSE)

Formula for D3 would be:

=VLOOKUP(RC[-2],Vendor!R2C5:R9C7,3,FALSE)

So scripts would be:

Sheet1.Range("C3:C" & Lastrow).Formula ="=VLOOKUP(RC[-1],Vendor!R2C5:R9C7,2,FALSE)"
Sheet1.Range("D3:D" & Lastrow).Formula ="=VLOOKUP(RC[-2],Vendor!R2C5:R9C7,3,FALSE)"

Open in new window


Thanks
Rob H
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Sparklines have been introduced with Excel 2010 and are a useful tool for creating small in-cell charts, used for example in dashboards. Excel 2010 offers three different types of Sparklines: Line, Column and Win/Loss. What it does not offer is a…
Introduction This Article briefly covers methods of calculating the NPV and IRR variants in Excel as well as the limitations in calculating and interpreting IRR results. Paraphrasing Richard Shockley, author of my favourite finance reference tex…
The viewer will learn how to use the =DISCRINV command to create a discrete random variable, use this command to model a set of probabilities and outcomes in a Monte Carlo simulation, and learn how to find the standard deviation of a set of probabil…
This Micro Tutorial will demonstrate on a Mac how to change the sort order for chart legend values and decrpyt the intimidating chart menu.

919 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now