Copying from active cell

chadski778

Active Member
Joined
Mar 14, 2010
Messages
297
I would like a macro for copying the contents of an active cell and pasting into 100 cells immediately below the active cell in the same column, if that is possible?
 

Excel Facts

Enter current date or time
Ctrl+: enters current time. Ctrl+; enters current date. Use Ctrl+: Ctrl+; Enter for current date & time.
That works great thanks. Could this be modified to include pasting all the way to the last occupied row in the spreadsheet?
 
Upvote 0
Code:
Sub CopyDown()
Dim myRow As Integer
Dim LastRow As Integer
Dim NewRows As Integer

myRow = ActiveCell.Row
LastRow = ActiveCell.End(xlDown).Row
NewRows = (LastRow - myRow) + 1
ActiveCell.Resize(NewRows, 1).Value = ActiveCell.Value
End Sub

If there are any blanks in your Col, it will break this.. Meaning

Col A

15
14
18
19
20

18

In that example, the code would only copy down to the row with 20. If you need it to skip blanks and find the absolute last row with data, regardless of any blanks in between...

Code:
Sub CopyDown()
Dim myRow As Integer
Dim LastRow As Integer
Dim NewRows As Integer
myRow = ActiveCell.Row
LastRow = ActiveSheet.Cells(65536, ActiveCell.Column).End(xlUp).Row
NewRows = (LastRow - myRow) + 1
ActiveCell.Resize(NewRows, 1).Value = ActiveCell.Value
End Sub
 
Upvote 0
That works if there is data in the column under the Active Cell but not if there are blank cells in the same column and occupied cells in another column. Sometimes I will have an actice cell with a column of blanks underneath. I need to fill these up to the last occupied row in the sheet eg active cell D1, data present in A1:A10000. Fill D2:D10000 with contents of active cell. (A1:A10000 is just arbitrary as an example)
 
Upvote 0
Code:
Sub CopyDown()
Dim myRow As Integer
Dim LastRow As Integer
Dim NewRows As Integer

myRow = ActiveCell.Row
LastRow = Cells.Find("*", SearchOrder:=xlByRows, SearchDirection:=xlPrevious).Row
NewRows = (LastRow - myRow) + 1
ActiveCell.Resize(NewRows, 1).Value = ActiveCell.Value
End Sub

This change will find the last used row, regardless of what column it's in.
 
Upvote 0

Forum statistics

Threads
1,224,602
Messages
6,179,848
Members
452,948
Latest member
UsmanAli786

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