Consulting

Results 1 to 11 of 11

Thread: Solved: VBA "Lookup"

  1. #1
    VBAX Regular
    Joined
    Feb 2013
    Posts
    41
    Location

    Solved: VBA "Lookup"

    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
    Attached Files Attached Files
    Last edited by Nec11; 04-01-2013 at 10:22 AM.

  2. #2
    Administrator
    VP-Knowledge Base
    VBAX Grand Master mdmackillop's Avatar
    Joined
    May 2004
    Location
    Scotland
    Posts
    14,489
    Location
    Use Evaluate if you only want the value
    [VBA]With rCell.Offset(0, 1)
    .Value =Evaluate( "=VLOOKUP(RC[-1],Sheet3!R2C1:R10000C2,2,FALSE)")[/VBA]
    MVP (Excel 2008-2010)

    Post a workbook with sample data and layout if you want a quicker solution.


    To help indent your macros try Smart Indent

    Please remember to mark threads 'Solved'

  3. #3
    VBAX Regular
    Joined
    Feb 2013
    Posts
    41
    Location
    tryed already, but.... not working

    P.S attached example in first post

  4. #4
    Administrator
    VP-Knowledge Base VBAX Grand Master mdmackillop's Avatar
    Joined
    May 2004
    Location
    Scotland
    Posts
    14,489
    Location
    [VBA] rcel.Offset(, 1).Value = Evaluate("=VLOOKUP(B" & rcel.Row & ",Sheet3!A1:B5000,2,FALSE)")
    [/VBA]
    MVP (Excel 2008-2010)

    Post a workbook with sample data and layout if you want a quicker solution.


    To help indent your macros try Smart Indent

    Please remember to mark threads 'Solved'

  5. #5
    VBAX Regular
    Joined
    Feb 2013
    Posts
    41
    Location
    Tryed you code but... still not working
    Attached Files Attached Files

  6. #6
    VBAX Tutor
    Joined
    Jan 2008
    Posts
    262
    Location
    How about removing the = sign in the evaluate function?

  7. #7
    Administrator
    VP-Knowledge Base VBAX Grand Master mdmackillop's Avatar
    Joined
    May 2004
    Location
    Scotland
    Posts
    14,489
    Location
    Event code deleted
    Attached Files Attached Files
    MVP (Excel 2008-2010)

    Post a workbook with sample data and layout if you want a quicker solution.


    To help indent your macros try Smart Indent

    Please remember to mark threads 'Solved'

  8. #8
    VBAX Regular
    Joined
    Feb 2013
    Posts
    41
    Location
    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.

  9. #9
    VBAX Regular
    Joined
    Feb 2013
    Posts
    41
    Location
    Quote Originally Posted by mdmackillop
    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.

  10. #10
    Administrator
    VP-Knowledge Base VBAX Grand Master mdmackillop's Avatar
    Joined
    May 2004
    Location
    Scotland
    Posts
    14,489
    Location
    [VBA]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[/VBA]
    MVP (Excel 2008-2010)

    Post a workbook with sample data and layout if you want a quicker solution.


    To help indent your macros try Smart Indent

    Please remember to mark threads 'Solved'

  11. #11
    VBAX Regular
    Joined
    Feb 2013
    Posts
    41
    Location
    GREAT!!!
    WORK'S LIKE CHARM

    THANK YOU SO MUCH!!!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •