vlookup result in formula not value

Costa_Mukhar

New Member
Joined
Jun 6, 2015
Messages
20
Hello experts, I am using the below code for a vlookup, it is working perfectly except that in the first cell it is giving the result in value not formula

Code:
Dim cellvalue As String
    Dim lookup_range As range
    Dim coupon As Single
    
    cellvalue = Worksheets("Cost report").range("B5")
    Set lookup_range = Worksheets("BA").range("D:H")
    
    coupon = Application.WorksheetFunction.VLookup(cellvalue, lookup_range, 5, False)
    range("C5:C" & range("B" & Rows.Count).End(xlUp).Row) = coupon

in cell C5, the result is in value, so when the macro applies the formula on the selected range, it is copying the same value in cell C5 to the entire range. how to keep the formula in the first cell, so it can apply it on the entire range then turn the entire column into values. I feel that there is something missing in the code, but I am not able to figure it out!!

Thanks in advnace
 

Excel Facts

Move date out one month or year
Use =EDATE(A2,1) for one month later. Use EDATE(A2,12) for one year later.
YES....I got it :) it feels amazing when you figure it by yourself ;)

Code:
Dim cellvalue As String
    Dim lookup_range As range
    Dim coupon As Single
    
    cellvalue = Worksheets("Cost report").range("B5:B" & Rows.Count).End(xlUp).Row
    Set lookup_range = Worksheets("BA").range("D:H")
    
    'coupon = Application.WorksheetFunction.VLookup(cellvalue, lookup_range, 5, False)
    'range("C5:C" & range("B" & Rows.Count).End(xlUp).Row) = coupon
    
    With Worksheets("cost report").range("C5:C" & range("B" & Rows.Count).End(xlUp).Row)
        .FormulaR1C1 = "=vlookup(RC[-1],'BA'!C4:C8,5,False)"
        .FormulaR1C1 = .Value
        
    End With
 
Upvote 0

Forum statistics

Threads
1,213,482
Messages
6,113,915
Members
448,532
Latest member
9Kimo3

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top