VBA to drag forumlas

asjmoron

Board Regular
Joined
Apr 26, 2016
Messages
98
Office Version
  1. 2016
Platform
  1. Windows
Hi All.

I am 99% of the way through a project and I can not figure this part out.

basically I start with the below...

VBA Code:
'Formulas
Range("L1").End(xlDown).Select
Selection.Copy

and from there I need it select whatever cell in L it lands on accross to R the drag the formulas in those cells to the last column with data in it (The cell will change as data is add to the sheet through an auto fill process so I can not say it will be L15 for example as it will be different with every update).

I have tried loads of things but keep getting it wrong so would be very greatful for any assistance!

As always, thanks so much for reading this and for any help.
 
Last edited:

Excel Facts

Ambidextrous Undo
Undo last command with Ctrl+Z or Alt+Backspace. If you use the Undo icon in the QAT, open the drop-down arrow to undo up to 100 steps.
I have gt one step further by changing the below..

VBA Code:
'Formulas
Range("L1").End(xlDown).Select
Range(Selection, Selection.End(xlToRight)).Select
Selection.Copy

but still need to work out how to drag this to the last column
 
Upvote 0
This is a first for me! No replies.

just incase anyone else has this issue, I have managed to suss the code out (albeit it may be a rather round aboutway to do it!) and wanted to share it.

basically, I could not find a way to select part of a row based on the first empty cell and drag the whole selection down so I used a series of repetitive vba to find each cell then a call to 'Sub Filld()'

The first part went like this....

Code:
'Formulas
Range("L1").End(xlDown).Select
Range(Selection, Selection.End(xlToRight)).Select

Call filld

Range("M1").End(xlDown).Select
Range(Selection, Selection.End(xlToRight)).Select

Call filld

Range("N1").End(xlDown).Select
Range(Selection, Selection.End(xlToRight)).Select

Call filld

Range("O1").End(xlDown).Select
Range(Selection, Selection.End(xlToRight)).Select

Call filld

Range("P1").End(xlDown).Select
Range(Selection, Selection.End(xlToRight)).Select

Call filld

Range("Q1").End(xlDown).Select
Range(Selection, Selection.End(xlToRight)).Select

Call filld

Range("R1").End(xlDown).Select
Range(Selection, Selection.End(xlToRight)).Select

Call filld

The this is the Filld() part

VBA Code:
Sub filld()
  If IsEmpty(ActiveCell) Then Exit Sub
  Range(ActiveCell, ActiveCell.Offset(0, -1).End(xlDown).Offset(0, 1)).FillDown
End Sub
 
Upvote 0
How about
VBA Code:
Sub asjmoron()
    Dim UsdRws As Long
    
    UsdRws = Range("A" & Rows.Count).End(xlUp).Row
    Range(Range("L" & Rows.Count).End(xlUp), Range("L" & UsdRws)).Resize(, 7).FillDown
End Sub
Ths uses col A to determine how far to fill down the formula, but that can easily be changed
 
Upvote 0

Forum statistics

Threads
1,214,959
Messages
6,122,476
Members
449,087
Latest member
RExcelSearch

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