PDA

View Full Version : Solved: VBA "Lookup"



Nec11
04-01-2013, 10:07 AM
Hello,

Can somebody to let me know an VBA code for Vlookup formula.
I don't wont something like:

With rCell.Offset(0, 1)
.Value = "=VLOOKUP(RC[-1],Sheet3!R2C1:R10000C2,2,FALSE)"

because this form it write in the cell formula and then the calculations are made.
Best Regards,
Nec

mdmackillop
04-01-2013, 10:14 AM
Use Evaluate if you only want the value
With rCell.Offset(0, 1)
.Value =Evaluate( "=VLOOKUP(RC[-1],Sheet3!R2C1:R10000C2,2,FALSE)")

Nec11
04-01-2013, 10:21 AM
tryed already, but.... not working

P.S attached example in first post

mdmackillop
04-01-2013, 11:12 AM
rcel.Offset(, 1).Value = Evaluate("=VLOOKUP(B" & rcel.Row & ",Sheet3!A1:B5000,2,FALSE)")

Nec11
04-01-2013, 11:24 AM
Tryed you code but... still not working

sassora
04-01-2013, 11:28 AM
How about removing the = sign in the evaluate function?

mdmackillop
04-01-2013, 11:38 AM
Event code deleted

Nec11
04-01-2013, 11:38 AM
Every time after complete column "B" I receive an message" Object Required" ?! with or without"=" sign in evaluate function

If somebody fix that code can you please attach it.
Thousand of thanks.

Nec11
04-01-2013, 11:51 AM
Event code deleted

Your code seams to be OK in this form, but as you can see mine original file was made to watch the last cell from column "B" and if an value appears vlookup that value and bring the necesary information.

mdmackillop
04-01-2013, 12:19 PM
Private Sub Worksheet_Change(ByVal Target As Excel.Range)
Sheet1.Unprotect
lastln = (Sheet2.Cells(Sheet2.Rows.Count, 1).End(xlUp).Row)
Dim rChange As Range
On Error GoTo ErrHandler
Set rChange = Intersect(Target, Range("B:B"))

If Not rChange Is Nothing Then
Application.EnableEvents = False
If Target > "" Then
For i = 1 To 8
Target.Offset(, i).Value = Evaluate("=VLOOKUP(B" & Target.Row & ",Sheet3!A1:G500," & i + 1 & ",FALSE)")
Next
End If
End If

ExitHandler:
Set rChange = Nothing
Application.EnableEvents = True
Exit Sub
ErrHandler:
MsgBox Err.Description
Resume ExitHandler
Sheet1.Protect

End Sub

Nec11
04-01-2013, 12:29 PM
GREAT!!!
WORK'S LIKE CHARM

THANK YOU SO MUCH!!!