Macro for copy and paste

vidplaylist

Board Regular
Joined
Aug 3, 2011
Messages
78
Every month i copy the formula to next column on many sheets. Each sheets has different number of rows. I tried a macro to copy and paste the formula on next column but every sheet has different numbers of total rows as a result it copy the formula on only number of columns which are part of recorded macro.

Can someone suggest a vba code that i can input the number of rows when i run macro on each sheet.

Sub formula1mrexcel()

' recorded macro
' copy formula to next column each month

Range("F3:F50").Select
Selection.Copy
ActiveWindow.SmallScroll Down:=-42
Range("G3").Select
ActiveSheet.Paste
Range("F3").Select
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
Application.CutCopyMode = False
End Sub



Thanks
 

Excel Facts

Can you sort left to right?
To sort left-to-right, use the Sort dialog box. Click Options. Choose "Sort left to right"
Try

Code:
Sub formula1mrexcel()

' recorded macro
' copy formula to next column each month
Dim LR As Long, LC As Long
LR = Cells.Find(What:="*", SearchDirection:=xlPrevious, SearchOrder:=xlByRows).Row
LC = Cells.Find(What:="*", SearchDirection:=xlPrevious, SearchOrder:=xlByColumns).Column
Range(Cells(3, LC), Cells(LR, LC)).Copy Destination:=Cells(3, LC + 1)
Cells(3, LC).PasteSpecial Paste:=xlPasteValues
Application.CutCopyMode = False
End Sub
 
Upvote 0

Forum statistics

Threads
1,224,595
Messages
6,179,798
Members
452,943
Latest member
Newbie4296

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