+ Reply to Thread
Results 1 to 7 of 7

Insert value from vlookup and not formula with VBA

  1. #1
    Les Stout
    Guest

    Insert value from vlookup and not formula with VBA

    Hi all, could you please advise me how to change the script below. The
    script inserts the Vlookup formulas and i was wondering if it is
    possible just to put in the values and not the formula. If this is
    possible, could you show me how to change the script.

    Sub Lookups()

    Dim myLookUpRng As Range
    Application.StatusBar = "Your prices are being compared to the
    supplier prices"
    Range("D4").Select
    With Workbooks(SuppFileNameC).Worksheets(SheetName)
    Set myLookUpRng = .Range("D:N")
    End With
    Do Until ActiveCell = ""
    ActiveCell.Offset(0, 8).FormulaR1C1 _
    = "=VLOOKUP(RC[-8]," _
    & myLookUpRng.Address(external:=True,
    ReferenceStyle:=xlR1C1) _
    & ",9,0)"
    ActiveCell.Offset(0, 9).FormulaR1C1 _
    = "=VLOOKUP(RC[-9]," _
    & myLookUpRng.Address(external:=True,
    ReferenceStyle:=xlR1C1) _
    & ",10,0)"
    ActiveCell.Offset(1, 0).Select
    Loop
    Range("A4").Select
    ' InsPriceDiff
    End Sub


    Thanks in advance.

    best regards,

    Les Stout

    *** Sent via Developersdex http://www.developersdex.com ***

  2. #2
    Bob Phillips
    Guest

    Re: Insert value from vlookup and not formula with VBA

    Instead of

    ActiveCell.Offset(0, 8).FormulaR1C1 _
    = "=VLOOKUP(RC[-8]," _
    & myLookUpRng.Address(external:=True,
    ReferenceStyle:=xlR1C1) _
    & ",9,0)"

    use

    With ActiveCell.Offset(0, 8)
    .FormulaR1C1 _
    = "=VLOOKUP(RC[-8]," _
    & myLookUpRng.Address(external:=True,ReferenceStyle:=xlR1C1) _
    & ",9,0)"
    .Value = .Value
    End With

    etc.


    --

    HTH

    RP
    (remove nothere from the email address if mailing direct)


    "Les Stout" <[email protected]> wrote in message
    news:O%[email protected]...
    > Hi all, could you please advise me how to change the script below. The
    > script inserts the Vlookup formulas and i was wondering if it is
    > possible just to put in the values and not the formula. If this is
    > possible, could you show me how to change the script.
    >
    > Sub Lookups()
    >
    > Dim myLookUpRng As Range
    > Application.StatusBar = "Your prices are being compared to the
    > supplier prices"
    > Range("D4").Select
    > With Workbooks(SuppFileNameC).Worksheets(SheetName)
    > Set myLookUpRng = .Range("D:N")
    > End With
    > Do Until ActiveCell = ""
    > ActiveCell.Offset(0, 8).FormulaR1C1 _
    > = "=VLOOKUP(RC[-8]," _
    > & myLookUpRng.Address(external:=True,
    > ReferenceStyle:=xlR1C1) _
    > & ",9,0)"
    > ActiveCell.Offset(0, 9).FormulaR1C1 _
    > = "=VLOOKUP(RC[-9]," _
    > & myLookUpRng.Address(external:=True,
    > ReferenceStyle:=xlR1C1) _
    > & ",10,0)"
    > ActiveCell.Offset(1, 0).Select
    > Loop
    > Range("A4").Select
    > ' InsPriceDiff
    > End Sub
    >
    >
    > Thanks in advance.
    >
    > best regards,
    >
    > Les Stout
    >
    > *** Sent via Developersdex http://www.developersdex.com ***




  3. #3
    Les Stout
    Guest

    Re: Insert value from vlookup and not formula with VBA

    Thanks Bob, have a great weekend.

    Les Stout

    *** Sent via Developersdex http://www.developersdex.com ***

  4. #4
    Les Stout
    Guest

    Re: Insert value from vlookup and not formula with VBA

    Hi Bob, must one loop down the sheet or is it possible to do it another
    way ?

    Les Stout

    *** Sent via Developersdex http://www.developersdex.com ***

  5. #5
    Bob Phillips
    Guest

    Re: Insert value from vlookup and not formula with VBA



    --

    HTH

    RP
    (remove nothere from the email address if mailing direct)


    "Les Stout" <[email protected]> wrote in message
    news:O%[email protected]...
    > Hi all, could you please advise me how to change the script below. The
    > script inserts the Vlookup formulas and i was wondering if it is
    > possible just to put in the values and not the formula. If this is
    > possible, could you show me how to change the script.
    >
    > Sub Lookups()
    >
    > Dim myLookUpRng As Range
    > Application.StatusBar = "Your prices are being compared to the
    > supplier prices"
    > Range("D4").Select
    > With Workbooks(SuppFileNameC).Worksheets(SheetName)
    > Set myLookUpRng = .Range("D:N")
    > End With
    > Do Until ActiveCell = ""
    > ActiveCell.Offset(0, 8).FormulaR1C1 _
    > = "=VLOOKUP(RC[-8]," _
    > & myLookUpRng.Address(external:=True,
    > ReferenceStyle:=xlR1C1) _
    > & ",9,0)"
    > ActiveCell.Offset(0, 9).FormulaR1C1 _
    > = "=VLOOKUP(RC[-9]," _
    > & myLookUpRng.Address(external:=True,
    > ReferenceStyle:=xlR1C1) _
    > & ",10,0)"
    > ActiveCell.Offset(1, 0).Select
    > Loop
    > Range("A4").Select
    > ' InsPriceDiff
    > End Sub
    >
    >
    > Thanks in advance.
    >
    > best regards,
    >
    > Les Stout
    >
    > *** Sent via Developersdex http://www.developersdex.com ***




  6. #6
    Bob Phillips
    Guest

    Re: Insert value from vlookup and not formula with VBA

    Hi Les,

    Try this

    Sub Lookups()

    Dim myLookUpRng As Range
    Dim i As Long

    Application.StatusBar = "Your prices are being compared to the supplier
    prices"
    Range("D4").Select
    With Worksheets(SheetName)
    Set myLookUpRng = .Range("D:N")
    End With
    For i = 4 To Cells(Rows.Count, "D").End(xlUp).Row
    Cells(i, "L").Value = Application.VLookup(Cells(i, "D").Value, _
    myLookUpRng, 9, 0)
    Cells(i, "L").Value = Cells(i, "L").Value
    Cells(i, "M").Value = Application.VLookup(Cells(i, "D").Value, _
    myLookUpRng, 10, 0)
    Next i
    Range("A4").Select
    ' InsPriceDiff
    End Sub


    --

    HTH

    RP
    (remove nothere from the email address if mailing direct)


    "Les Stout" <[email protected]> wrote in message
    news:[email protected]...
    > Hi Bob, must one loop down the sheet or is it possible to do it another
    > way ?
    >
    > Les Stout
    >
    > *** Sent via Developersdex http://www.developersdex.com ***




  7. #7
    Les Stout
    Guest

    Re: Insert value from vlookup and not formula with VBA

    Hi Bob, sorry about the time delay due to time differences.
    Thanks a million works 100%

    best regards,

    Les Stout

    *** Sent via Developersdex http://www.developersdex.com ***

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

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

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1