Copy a Formula in a Loop

Lauren123

New Member
Joined
Mar 16, 2018
Messages
28
I have this formula, but if is more than to rows it doesnt work, maybe on a loop it will work, someone knows how to do it?

Sub CopiaSuma()
ThisWK = ThisWorkbook.Name


LastRows = Sheets("Draft").Range("C" & Rows.Count).End(xlUp).Row




Workbooks(ThisWK).Worksheets("Draft").Range("P7").Copy
Workbooks(ThisWK).Worksheets("Draft").Range("P8" & LastRows).PasteSpecial


End Sub
 

Excel Facts

Test for Multiple Conditions in IF?
Use AND(test, test, test, test) or OR(test, test, test, ...) as the logical_test argument of IF.
How about
Code:
Sub CopiaSuma()
thiswk = ThisWorkbook.name

lastrows = Sheets("Draft").Range("C" & Rows.Count).End(xlUp).Row
Workbooks(thiswk).Worksheets("Draft").Range("P7:P" & lastrows).FillDown

End Sub
 
Upvote 0
also
Code:
Sub CopiaSuma()
Dim LastRows As Long
 LastRows = Sheets("Draft").Range("C" & Rows.Count).End(xlUp).Row
 Worksheets("Draft").Range("P7").Copy Worksheets("Draft").Range("P8" & LastRows)
 End Sub
 
Last edited:
Upvote 0
@JLGWhiz
I think that should be
Code:
Worksheets("Draft").Range("P8[COLOR=#ff0000]:P[/COLOR]" & LastRows)
 
Upvote 0
Hey, thanks a lot, but I change it because I wanted it to always copy the value on P7, it worked once but it had a bug I dont know what is wrong, can you hel please?
Sub CopiaSuma()


Dim rng As Range


ThisWK = ThisWorkbook.Name
LastRows = Sheets("Draft").Range("C" & Rows.Count).End(xlUp).Row
Set rng = Workbooks(ThisWK).Worksheets("Draft").Range("P7" & LastRows).FillDown

If LastRows < 7 Then
rng.Select
Else
rng.Paste
End If


End Sub
 
Upvote 0

Forum statistics

Threads
1,224,752
Messages
6,180,742
Members
452,996
Latest member
nelsonsix66

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