Loop paste cels with formula

Marlowwe

New Member
Joined
Jan 12, 2016
Messages
46
Hey guys,

i would like to ask you for help. Icreating macro to copy cell (with formula) to right cell (it will be variable- 3 or 4 cells etc.) from multiple selection.

And also should be variable how many times it will be copied

ABCDEFGHI
1=SUM(A2:A3 )
21
32
4
5=SUM(A6:A7 )
63
74

<tbody>
</tbody>

After macro should be like this:
Variables:
  • 2x copy to right
  • offset 2

ABCDEFGHI
1=SUM(A2:A3 )=SUM(C2:C3)=SUM(E2:E3)
21
32
4
5=SUM(A6:A7 )=SUM(C6:C7)=SUM(E6:E7)
63
74

<tbody>
</tbody>




My try is this, but it doesnt work. it copy only once and with the exact formula from original cell.

Code:
Sub Formula_multiCopy()
Dim rng As Range


' The looping routine
Set rng = Selection
Do Until IsEmpty(rng)
    rng.Offset(, 2) = rng.Formula
        
    Selection.PasteSpecial Paste:=xlPasteFormats, Operation:=xlNone, _
    SkipBlanks:=False, Transpose:=False
    Application.CutCopyMode = False
Loop
End Sub

Thank you for your help
 
I am not sure if I can. I have like 200 macros in my Personal.xlsb. How I can check this in other macros ?



Not sure why you would get that & cannot replicate it here.
Could you check all the code in your Personal.xlsb & see if you have declared either Rows or Count as a variable.
 
Upvote 0

Excel Facts

Excel Can Read to You
Customize Quick Access Toolbar. From All Commands, add Speak Cells or Speak Cells on Enter to QAT. Select cells. Press Speak Cells.
Open the VBE > Ctrl F > select current Project > in Find What type "Dim row" > Ensure the 3 checkboxes below direction are unchecked > Click Find Next.
Do the same for Dim Count, Sub Row, & Sub Count
 
Upvote 0

Forum statistics

Threads
1,214,606
Messages
6,120,483
Members
448,967
Latest member
visheshkotha

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