Copy 2 cells Dynamically and AutoFill down.

JohnZ1156

Board Regular
Joined
Apr 10, 2021
Messages
153
Office Version
  1. 2021
Platform
  1. Windows
I have this VBA Script to copy "F1829:F1830" then AutoFill down the column to the last cell in the table.
Rather than always point to "F1829:F1830", I'd like it to be dynamic up an even number of cells up from the last row.

Sheets("Investments").Select
LR = Cells(Rows.Count, 1).End(xlUp).Row
Range("F1829:F1830").AutoFill Range("F1829:F" & LR), Type:=xlFillCopy

For example:
Goto last cell in Column F, go up 5 cells, copy that cell and the cell below it, AutoFill down to last cell in the column.
 

Excel Facts

Difference between two dates
Secret function! Use =DATEDIF(A2,B2,"Y")&" years"&=DATEDIF(A2,B2,"YM")&" months"&=DATEDIF(A2,B2,"MD")&" days"
Are you actually working with an official Excel "table" (that already had pre-defined rows and columns) or are you really just working with a data list?
What exactly is in these cells you are trying to autofill? Hard-coded values, or formulas?
If formulas, what exactly do those formulas look like?
 
Upvote 0
That is an answer to one of the questions I asked.
What about the others?
Well, as they say, there's more than one way to skin a cat.
I figured out another solution.
Thank you for your help and follow up.
 
Upvote 0
Please post the solution you used.
Then you can mark that as the solution.
 
Upvote 0
For some reason, if I add a row of data to the bottom of my table, Excel is not copying down the formulas to the new row correctly.
BTW, yes, I checked all the checkboxes in the options settings. That's not the problem.

I'm using the OFFSET Function in VBA to find the last record of data, go up 5 rows and over 5 columns, copy 2 cells to clipboard, go down 2 cells, paste and go down 2 more cells and paste again.

Sheets("SheetName").Select
Range("A1").Select
Application.Goto Reference:="R10C1"
Selection.End(xlDown).Select
ActiveCell.Offset(-5, 5).Select
Range(ActiveCell.Offset(0, 0), ActiveCell.Offset(1, 0)).Select
Selection.Copy
ActiveCell.Offset(2, 0).Select
Selection.PasteSpecial Paste:=xlPasteFormats
Selection.PasteSpecial Paste:=xlPasteFormulas
ActiveCell.Offset(2, 0).Select
Selection.PasteSpecial Paste:=xlPasteFormats
Selection.PasteSpecial Paste:=xlPasteFormulas
Application.CutCopyMode = False

Then I'm doing a similar process except copying a range of 8 cells, moving down and pasting.
It works, and it's dynamic regardless of how many more rows of data are added to the table.

There may be an easier way, or a shorter way of writing the VBA script, but I'm still a novice.

Thank you to all who viewed my post and offered suggestions.
 
Upvote 0
Solution

Forum statistics

Threads
1,214,651
Messages
6,120,744
Members
448,989
Latest member
mariah3

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