Link to home
Start Free TrialLog in
Avatar of leezac
leezac

asked on

Vlookup not Inserting Correctly

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
Avatar of Anne Troy
Anne Troy
Flag of United States of America image

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)
Avatar of leezac
leezac

ASKER

Ok - I changed, but put B3 in C3 and C4.  Need for it to copy down B3, B4 B5 etc.
ASKER CERTIFIED SOLUTION
Avatar of Rob Henson
Rob Henson
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial