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

How can you automate Excel?
Press Alt+F11 from Windows Excel to open the Visual Basic for Applications (VBA) editor.
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
 
Upvote 0
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
 
Upvote 0

Forum statistics

Threads
1,214,601
Messages
6,120,462
Members
448,965
Latest member
grijken

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