Hi,
I have written a short piece of code that identifies a target cell, inserts a row above it, then moves two cells up from the target cell. It then selects the current active cell and the three cells to the right and autofills down two rows.
The code does exactly what I want it to do, but I have 2 questions:
1) I don't understand why the last part of the second line of the code (Range("A1:D1").select) selects the two cells to the right of the active cell. It seems like it should be selecting the actual range A1:D1? I used the macro recorder to get this part of the code which is why I don't understant it. Again, it does exactly what I want, I'm just confused as to how.
2) Is there a more effecient way to write this code. I generally try to stay away from selecting cells but this is the only way I could figure out how to do it.
The code is below.
Any input would be appreciated. Thank you.
I have written a short piece of code that identifies a target cell, inserts a row above it, then moves two cells up from the target cell. It then selects the current active cell and the three cells to the right and autofills down two rows.
The code does exactly what I want it to do, but I have 2 questions:
1) I don't understand why the last part of the second line of the code (Range("A1:D1").select) selects the two cells to the right of the active cell. It seems like it should be selecting the actual range A1:D1? I used the macro recorder to get this part of the code which is why I don't understant it. Again, it does exactly what I want, I'm just confused as to how.
2) Is there a more effecient way to write this code. I generally try to stay away from selecting cells but this is the only way I could figure out how to do it.
The code is below.
Code:
Range("Target.Cell").EntireRow.Insert
Range("Target.Cell").Offset(-2, 0).Range("A1:D1").Select
Selection.AutoFill Destination:=Range(Selection, Selection.Offset(2, 0))
Any input would be appreciated. Thank you.