Hi,
I have a macro, that will add records to my table using vertical lookup formulas in several columns from data in another worksheet.
Before I run the macro, I add the record-id's for the new records in column A.
Then I run the macro.
Everything runs smoothly, until the Autofill copies the formulas from the first new record down to the last new record.
What do I need to change in the code, to make the autofill do it's job correctly?
Attached are two Screenshots. One with my code (snap2.jpg) and one with a view of part of my table (snap1.jpg)
Snap1.jpg
Snap2.jpg.
Sub Gegevens_uit_Sapdump_ophalen()
Dim LastRow1 As Long
LastRow1 = Range("A" & Rows.Count).End(xlUp).Row
Range("A" & LastRow1).Select
Range(Selection, Selection.End(xlUp)).Select
ActiveCell.Select
ActiveCell.Offset(0, 3).Select
ActiveCell.FormulaR1C1 = "=VLOOKUP(RC1,art_StoreServer.txt!C1:C15,6,0)"
ActiveCell.Offset(0, 1).Select
ActiveCell.FormulaR1C1 = "=VLOOKUP(RC1,art_StoreServer.txt!C1:C15,3,0)"
ActiveCell.Offset(0, 6).Select
ActiveCell.FormulaR1C1 = "=VLOOKUP(RC1,art_StoreServer.txt!C1:C15,7,0)"
ActiveCell.Offset(0, 3).Select
ActiveCell.FormulaR1C1 = "=VLOOKUP(RC1,art_StoreServer.txt!C1:C15,10,0)"
ActiveCell.Offset(0, 1).Select
ActiveCell.FormulaR1C1 = "=VLOOKUP(RC1,art_StoreServer.txt!C1:C15,11,0)"
ActiveCell.Offset(0, 3).Select
ActiveCell.FormulaR1C1 = "=VLOOKUP(RC1,art_StoreServer.txt!C1:C15,14,0)"
ActiveCell.Offset(0, 3).Select
ActiveCell.FormulaR1C1 = "=VLOOKUP(RC1,art_StoreServer.txt!C1:C15,2,0)"
Range("D" & LastRow1).Select
Range(Selection, Selection.End(xlUp)).Select
ActiveCell.Select
Range(ActiveCell, ActiveCell.Offset(0, 17)).Select
Selection.AutoFill Destination:=Range(Selection & LastRow1)
Selection.Copy
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
Columns("A:D").Select
Selection.EntireColumn.Hidden = False
End Sub
Bookmarks