Double Click Fill Handle - Macro Equivalent

pgrad

Board Regular
Joined
Dec 8, 2010
Messages
60
Hi All,

I am trying to replicate a formula across the worksheet rather than down as a small part of a macro.

Code:
Dim rng as Range 
set rng = Range(cells(2,1),cells(2,1).End(xlDown)) 
rng.offset(0,1).Formula = Cells(2,2).Formula

It copies down just fine, so I thought I would replace the xldown with xlToRight.

Code:
Dim rng as Range 
set rng = Range(cells(2,1),cells(2,1).End(xlToRight)) 
rng.offset(0,1).Formula = Cells(2,2).Formula

Sadly I out of my depth now so was hoping someone could show me the next step.

I'm getting an Application Defined or Object Defined Error on this code -

Code:
rng.offset(0,1).Formula = Cells(2,2).Formula

Thanks
Paul
 

Excel Facts

Whats the difference between CONCAT and CONCATENATE?
The newer CONCAT function can reference a range of cells. =CONCATENATE(A1,A2,A3,A4,A5) becomes =CONCAT(A1:A5)
Code:
Sub heres_for_you_to_change()
    'this is just to show you how it can work
    Cells(1, 1).Formula = "a1's formula"
    Range(Cells(1, 2), Cells(1, 10)).Formula = Cells(1, 1).Formula
End Sub
 
Upvote 0
Hey,

Thanks for your quick reply! Apologies I was away from my desk most of the day so have only just got back on with this.

I am afraid to say I could not adapt what you have provided to suit my needs. Perhaps you could explain what the code is doing, in laymans terms?

Alternativley I have almost got a workaround but cannot figure out how to pull the row number from the active cell part of my code.

Code:
'Sum up columns below last row
Last_Row = ActiveSheet.Range("b65536").End(xlUp).Row
ActiveSheet.Range("B" & Last_Row + 1).Formula = "=Sum(B1:B" & Last_Row & ")" ' Change B to whatever column you need to sum up.
 
'Finds last used cell in column b
Range("B65536").End(xlUp).Select
 
'Replicates formula across sheet
Selection.Copy
    Range("C4:IV4").Select
    Selection.PasteSpecial Paste:=xlPasteFormulas
    Calculate

Row 4 could potentially be any row from 1 to 10000, and I will need to sum up every column in b:iv.

Thanks again fro looking at this!

Paul
 
Upvote 0

Forum statistics

Threads
1,224,586
Messages
6,179,729
Members
452,939
Latest member
WCrawford

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