Solved

Vlookup not Inserting Correctly

Posted on 2014-01-29
3
201 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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 33

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

Independent Software Vendors: 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!

Question has a verified solution.

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

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…
Excel can be a tricky bit of software to get your head around. Whilst you’ll be able to eventually get to grips with the basic understanding of how to get by, there are a few Excel tips that not everybody will even know about let alone know how to d…
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…
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

695 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