Drag formula up dynamically

RioDegenero

New Member
Joined
Mar 1, 2023
Messages
23
Office Version
  1. 365
  2. 2021
Platform
  1. Windows
  2. MacOS
Hi,

Any help on VBA code to "drag up" formula or "copy" formula up dynamically will be appreciated.

I will like to drag the formula in cell B25 up until B2 preferably (if not then B1 is fine). The starting row will not always be cell B25 every time as per the picture below. So I need the formula to be dynamic.
The formula is "EOMonth(B26,1)"
Recording the code, I have this:
Range("B25").Select
Selection.AutoFill Destination: = Range("B2:B25"), Type: = xlFillDefault
Range("B2:B25").Select


1678447699029.png
 

Excel Facts

Lock one reference in a formula
Need 1 part of a formula to always point to the same range? use $ signs: $V$2:$Z$99 will always point to V2:Z99, even after copying
How about
VBA Code:
Sub RioDegenero()
    Range("B2:B25").FillUp
End Sub
 
Upvote 0
Have you tried xlFillCopy as the type parameter?

VBA Code:
Range("B25").AutoFill Destination:=Range("B2:B25"), Type:=xlFillCopy
Thanks for the suggestion. No I have not tried it, I want it to be dynamic because the starting cell will not always be B25. It could be B40 in an instance or B15 in another
 
Upvote 0
Have you tried xlFillCopy as the type parameter?

VBA Code:
Range("B25").AutoFill Destination:=Range("B2:B25"), Type:=xlFillCopy
Thanks for the suggestion. I want it to be dynamic because the starting cell will not always be B25. It could be B40 in an instance or B15 in another
 
Upvote 0
Thanks for the suggestion. No I have not tried it, I want it to be dynamic because the starting cell will not always be B25. It could be B40 in an instance or B15 in another
My answer is not about the range.
Please just change the xlFillDefault parameter in your own code to xlFillCopy. My answer is about the Type parameter of the AutoFill function. You don't have to use my code line.
.
 
Upvote 0
My answer is not about the range.
Please just change the xlFillDefault parameter in your own code to xlFillCopy. My answer is about the Type parameter of the AutoFill function. You don't have to use my code line.
.
Thanks
How can I select the range between the active cell and B2?
 
Upvote 0
How about
VBA Code:
Sub RioDegenero()
   Range("B2", Range("B2").End(xlDown)).FillUp
End Sub
 
Upvote 0
Solution
Glad we could help & thanks for the feedback.
 
Upvote 0

Forum statistics

Threads
1,215,140
Messages
6,123,266
Members
449,093
Latest member
Vincent Khandagale

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