Excel Macro - Copying Vlookup formula down to last cell

wardie

New Member
Joined
Aug 28, 2014
Messages
3
Currently I am trying to automate a report build that can have a different number of rows each time it is run (weekly)

Column A has the list of devices found.

Columns B & C have data but not consistent (lots of blanks).

Columns D - T are vlookups that I would manually drag down to the last cell of Column A each time.

I'm trying to macro the copying of the vlookup formula to the last row but am stuck trying to find the code to do my task.

My current bad code for this copies down to the last row of the spreadsheet.

Sheets("ServerList").Activate
Range("D2").Select
ActiveCell.FormulaR1C1 = "=VLOOKUP(RC[-1],Working_FACTS!C[-3]:C[-1],3,0)"
Range("D2").Select
Selection.Copy
* Range(ActiveCell, ActiveCell.End(xlDown)).Select
ActiveSheet.Paste
Range("D2").Select
* Range(ActiveCell, ActiveCell.End(xlDown)).Select
Selection.Copy
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False

The lines with the * are the ones I need to fix. I need to capture the last cell # in Column A and transpose it to my Range.Select

Anybody with greater smarts than me like to suggest the easy fix??

Many Thanks

Wardie
 

Excel Facts

Lock one reference in a formula
Need 1 part of a formula to always point to the same range? use $ signs: $V$2:$Z$99 will always point to V2:Z99, even after copying
Try

Code:
Dim LR As Long
Sheets("ServerList").Activate
LR = Range("A" & Rows.Count).End(xlUp).Row
Range("D2").FormulaR1C1 = "=VLOOKUP(RC[-1],Working_FACTS!C[-3]:C[-1],3,0)"
Range("D2").AutoFill Destination:=Range("D2:D" & LR)
 
Upvote 0
Thank you VoG, that has solved my problem.

I knew it would be easy but had hit a mental road block
 
Upvote 0

Forum statistics

Threads
1,214,905
Messages
6,122,175
Members
449,071
Latest member
cdnMech

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