Stop Macro

JimmyA

New Member
Joined
Jun 28, 2018
Messages
2
Hi I have a macro which is copying and pasting a vlookup.

How do I get it top running hen the data the spreadsheet runs out? instead of giving it an line number to end on as below:

Sub vlookup()
'
' vlookup Macro
'
'
Range("N2").Select
ActiveCell.FormulaR1C1 = "=VLOOKUP(RC[-13],Lookup!C[-9]:C[-6],4,FALSE)"
Range("P2").Select
ActiveCell.FormulaR1C1 = "=VLOOKUP(RC[-15],Lookup!C[-11]:C[-9],3,FALSE)"
Range("Q2").Select
ActiveCell.FormulaR1C1 = "=VLOOKUP(RC[-16],Lookup!C[-12]:C[-6],7,FALSE)"
Range("R2").Select
ActiveCell.FormulaR1C1 = "=VLOOKUP(RC[-17],Lookup!C[-13]:C[-6],8,FALSE)"
Range("S2").Select
ActiveCell.FormulaR1C1 = "=VLOOKUP(RC[-18],Lookup!C[-14]:C[-6],9,FALSE)"
Range("N2:S2").Select
Selection.Copy
Range("N3:N6000").Select
ActiveSheet.Paste
Application.CutCopyMode = False
Range("N2").Select
Columns("N:N").EntireColumn.AutoFit
Columns("P:P").EntireColumn.AutoFit
Range("T2").Select
Columns("Q:Q").EntireColumn.AutoFit
Range("U2").Select
Columns("R:R").EntireColumn.AutoFit
Columns("S:S").EntireColumn.AutoFit
Range("N1").Select
End Sub



Thanks Jimmy
 

Excel Facts

Enter current date or time
Ctrl+: enters current time. Ctrl+; enters current date. Use Ctrl+: Ctrl+; Enter for current date & time.
Hi & welcome to MrExcel
How about
Code:
Sub vlookupmacro()
   Dim Lr As Long
   
   Lr = Range("A" & Rows.Count).End(xlUp).row
   Range("N2:N" & Lr).FormulaR1C1 = "=VLOOKUP(RC[-13],Lookup!C[-9]:C[-6],4,FALSE)"
   Range("P2:P" & Lr).FormulaR1C1 = "=VLOOKUP(RC[-15],Lookup!C[-11]:C[-9],3,FALSE)"
   Range("Q2:Q" & Lr).FormulaR1C1 = "=VLOOKUP(RC[-16],Lookup!C[-12]:C[-6],7,FALSE)"
   Range("R2:R" & Lr).FormulaR1C1 = "=VLOOKUP(RC[-17],Lookup!C[-13]:C[-6],8,FALSE)"
   Range("S2:S&lr").FormulaR1C1 = "=VLOOKUP(RC[-18],Lookup!C[-14]:C[-6],9,FALSE)"
   Columns("N:N").EntireColumn.AutoFit
   Columns("P:P").EntireColumn.AutoFit
   Columns("Q:Q").EntireColumn.AutoFit
   Columns("R:R").EntireColumn.AutoFit
   Columns("S:S").EntireColumn.AutoFit
   Range("N1").Select
End Sub
 
Upvote 0
Glad to help & thanks for the feedback
 
Upvote 0

Forum statistics

Threads
1,223,164
Messages
6,170,444
Members
452,326
Latest member
johnshaji

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