Copying a formula down a column to the last row with data

maclachlan

New Member
Joined
Dec 28, 2005
Messages
32
I apologize if this questions has been asked before on the forum. I did a search but couldn't find anything. I have a spreadsheet with 3 columns.

Column A contains a data pull with the number of rows changing each time the data is refreshed.
Columns B and C contain a formula that needs to be copied from row 5 down the spreadsheet. I would like the formula to be copied 1 row up from the last data of column A

Example

_A_________B_____________C
5_567_____+A5*$A$1____+A5*$C$1
6_1064____+A6*$A$1____+A6*$C$1
7_579_____+A7*$A$1____+A7*$C$1
...
50_1068___+A50*$A$1___+A50*$C$50
51_End**_____no formulas on this line


Code:
Private Sub CommandButton1_Click()

Worksheets("Sheet4").Activate
ActiveWorkbook.Sheets(4).Range("b5:c5").Copy
ActiveSheet.Paste Destination:=Worksheets("Sheet4").Range("b6", Range("a6",End(x1Down))


End Sub
 

Some videos you may like

Excel Facts

How can you automate Excel?
Press Alt+F11 from Windows Excel to open the Visual Basic for Applications (VBA) editor.

Norie

Well-known Member
Joined
Apr 28, 2004
Messages
76,218
Office Version
  1. 365
Platform
  1. Windows
Try this.
Code:
Private Sub CommandButton1_Click()
Dim LastRow as Long
With Worksheets("Sheet4")
     LastRow = .Range("A" & Rows.Count).End(xlUp).Row-1
     .Range("b5:c5").Copy .Range("b6:B" & LastRow)
End With
End Sub
 

Watch MrExcel Video

Forum statistics

Threads
1,122,518
Messages
5,596,622
Members
414,082
Latest member
sasmita

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