[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

Vlookup not Inserting Correctly

Posted on 2014-01-29
3
Medium Priority
?
206 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 2000 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

On Demand Webinar: Networking for the Cloud Era

Ready to improve network connectivity? Watch this webinar to learn how SD-WANs and a one-click instant connect tool can boost provisions, deployment, and management of your cloud connection.

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 …
Access developers frequently have requirements to interact with Excel (import from or output to) in their applications.  You might be able to accomplish this with the TransferSpreadsheet and OutputTo methods, but in this series of articles I will di…
This Micro Tutorial demonstrates how to create Excel charts: column, area, line, bar, and scatter charts. Formatting tips are provided as well.
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…

656 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