I have a string of steps I turned into one macro. When run independently they are all fine but something happens on step 18 when it is run collectively that is causing a problem where the "place I am pasting to is not the same size as my copy". Can any of you help? My code should be okay as it behaves properly when I select step 18 specifically but I'm sure I'm doing something horribly wrong. This is my first time using VBA so anything helps! The goal of this is to filldown a vlookup statement to a dynamic range in columns P,Q, and R (Column R takes its values from another sheet within the workbook) The place it says it gets stuck on is:
"Range("P2:P" & LR).PasteSpecial xlPasteAll"
For reference here is the step before 18 and step 18's code:
Step 17:
Sub Step17_2()
'
' Step17_2 Macro
'
'
Columns("C:C").Select
Application.CutCopyMode = False
Selection.Delete Shift:=xlToLeft
Columns("D:M").Select
Selection.Delete Shift:=xlToLeft
Columns("E:E").Select
Range(Selection, Selection.End(xlToRight)).Select
Selection.Delete Shift:=xlToLeft
End Sub
Step 18:
Sub Step18()
'
' Step18 Macro
'
'
Sheets("Contact").Select
Range("P1").Select
ActiveCell.FormulaR1C1 = "VlookupType"
Range("Q1").Select
ActiveCell.FormulaR1C1 = "VlookupIP"
Range("R1").Select
ActiveCell.FormulaR1C1 = "VlookupMailingName"
Range("P1").Select
Application.CutCopyMode = False
Application.CutCopyMode = False
Dim LR As Integer
LR = Range("A" & Rows.Count).End(xlUp).Row
Range("P2").Formula = "=VLOOKUP(A2,PastedValues!A$2:D$" & LR & ",2,FALSE)"
Range("P2").Copy
Range("P2:P" & LR).PasteSpecial xlPasteAll
Application.CutCopyMode = False
Range("Q2").Formula = "=VLOOKUP(A2,PastedValues!A$2:D$" & LR & ",4,FALSE)"
Range("Q2").Copy
Range("Q2:Q" & LR).PasteSpecial xlPasteAll
Application.CutCopyMode = False
Sheets("ContactDetailed").Select
Dim TA As Integer
TA = Range("A" & Rows.Count).End(xlUp).Row
Sheets("Contact").Select
Range("R2").Formula = "=VLOOKUP(A2,ContactDetailed!A$2:D$" & TA & ",4,FALSE)"
Range("R2").Copy
Range("R2:R" & LR).PasteSpecial xlPasteAll
Application.CutCopyMode = False
End Sub