Vlookup question

Costa_Mukhar

New Member
Joined
Jun 6, 2015
Messages
20
Hello experts,

Code:
Sub Bond_Accruals()

    With Worksheets("cost report").Range("C5:C" & Range("A" & Rows.Count).End(xlUp).Row)
            .FormulaR1C1 = "=vlookup(RC[-1],'BA'!C4:C8,5,False)"
            .FormulaR1C1 = .Value
    End With

End Sub

I am using the above code for a vlookup and it is working fine, but when applying the formula on the range, it is applying it on one more cell. Range("A:A") is till row 15, but it applies the formula till row 16 in Range("C:C").
Is there something wrong with the code? appreciate you help....thanks
 
Last edited:

Excel Facts

Control Word Wrap
Press Alt+Enter to move to a new row in a cell. Lets you control where the words wrap.

GCExcel

New Member
Joined
Apr 11, 2013
Messages
48
I don't see a problem with your code. It should place the value in C5:C15 only.

Is cell A16 really empty of there is a trailing space?
 
Upvote 0

Costa_Mukhar

New Member
Joined
Jun 6, 2015
Messages
20
no, there is nothing there, the cell is empty.
I am filling the data in column A using the below code, it is a normal copy.paste

Code:
Range("E6").Select
Range(Selection, Selection.End(xlDown)).Copy
Worksheets("Cost report").Range("A5").PasteSpecial Paste:=xlPasteValues
 
Upvote 0

GCExcel

New Member
Joined
Apr 11, 2013
Messages
48
if you type

Code:
msgbox [COLOR=#333333]Worksheets("cost report").Range("C5:C" & Range("A" & Rows.Count).End(xlUp).Row).address[/COLOR]
what result do you have?

Note:
You should avoid using .Select in as it slows down your code. Try this instead :
Code:
Range("E6:E" & Range("E6").End(xlDown).Row).Copy
 
Upvote 0

Forum statistics

Threads
1,195,629
Messages
6,010,774
Members
441,569
Latest member
PeggyLee

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
Top