Pasting Cells into a Bariable Range using VB

AndrewKent

Well-known Member
Joined
Jul 26, 2006
Messages
889
Hi there folks,

I'll try and keep this as simple as possible. I'm looking to write a macro that will past a formula down a column for as many rows as there is information in the adjacent column. So for example, cells A3 to A12 has data in them (however this could vary) and I wish to paste a formula from A1 into every cell adjacent to this range and when it reaches A13 (which in this example will be blank) the macro ends.

How do I do this?

Many thanks in advance,

Andy
 

Excel Facts

Can you AutoAverage in Excel?
There is a drop-down next to the AutoSum symbol. Open the drop-down to choose AVERAGE, COUNT, MAX, or MIN

Datsmart

Well-known Member
Joined
Jun 19, 2003
Messages
7,985
Hard to tell what column you want the formulae from cell A1 pasted.
The following code will paste A1's formula to column B starting in cell B3 down to the last row that data exists in column A.
Code:
Sub Macro2()
    'Clear old formula
    Range("B3:B" & Range("B65536").End(xlUp).Row & "").ClearContents
    
    'assign new formula
    Range("A1").Copy
    Range("B3:B" & Range("A65536").End(xlUp).Row & "").Select
    Selection.PasteSpecial Paste:=xlPasteFormulas, Operation:=xlNone, _
        SkipBlanks:=False, Transpose:=False
    Application.CutCopyMode = False
End Sub
 

AndrewKent

Well-known Member
Joined
Jul 26, 2006
Messages
889
Thank you mate,

I've only just had a chance to look at this and I've adapted it to my document and it seems to work fine. Thank you!

Andy
 

Forum statistics

Threads
1,141,918
Messages
5,709,339
Members
421,630
Latest member
MJ79

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
Top