ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Selecting & Pasting Dynamic Ranges (https://www.excelbanter.com/excel-programming/316989-selecting-pasting-dynamic-ranges.html)

GerryM[_2_]

Selecting & Pasting Dynamic Ranges
 
I have a sheet with 10000 rows but this can vary. Columns
A to C always have text in all rows. I want to paste a
value from Row 2 column A to all rows in Column D. As the
number of rows can vary how can I do this with a macro
with having to manually tell it how many rows there are.

GerryM

Don Guillett[_4_]

Selecting & Pasting Dynamic Ranges
 
from a post of mine a few minutes ago

determine your last row with something like
lr=cells(rows.count,"a").end(xlup).row


--
Don Guillett
SalesAid Software

"GerryM" wrote in message
...
I have a sheet with 10000 rows but this can vary. Columns
A to C always have text in all rows. I want to paste a
value from Row 2 column A to all rows in Column D. As the
number of rows can vary how can I do this with a macro
with having to manually tell it how many rows there are.

GerryM




ManualMan

Selecting & Pasting Dynamic Ranges
 
Try this:

Sub FillColD()

Dim RowCount As Long, i As Long

For i = 2 To (Cells(Rows.Count, "A").End(xlUp).Row)
Cells(i, 4).Value = Cells(2, 1).Value
Next i

End Sub


Regards,
ManualMan
http://www.gamesXL.tk


GerryM[_2_]

Selecting & Pasting Dynamic Ranges
 
This almost works, however the cell content I want to copy
is a formula and I want to copy the formula


-----Original Message-----
Try this:

Sub FillColD()

Dim RowCount As Long, i As Long

For i = 2 To (Cells(Rows.Count, "A").End(xlUp).Row)
Cells(i, 4).Value = Cells(2, 1).Value
Next i

End Sub


Regards,
ManualMan
http://www.gamesXL.tk

.


ManualMan

Selecting & Pasting Dynamic Ranges
 
Ah! Well, change the .Value attribute into .Formula
Works here!

Regards,
ManualMan
http://www.gamesXL.tk



All times are GMT +1. The time now is 06:39 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com