ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Repeat code over 300 rows (https://www.excelbanter.com/excel-programming/348886-repeat-code-over-300-rows.html)

Patrick Simonds

Repeat code over 300 rows
 
How can I alter this code so that if performs the function not just on row 2
but all the way down through row 300. I Am sure I could repeat the code for
each of the 300 rows but I bet there is a better way.

Private Sub Worksheet_Calculate()
Me.Range("A2").Value = Me.Range("D2")
End Sub



Tim Williams

Repeat code over 300 rows
 
for i=2 to 300
me.cells(i,1).value=me.cells(i,4).value
next i

though it's not clear from your post whether A3 should equal D2 or D3....


Tim



"Patrick Simonds" wrote in message
...
How can I alter this code so that if performs the function not just on row
2 but all the way down through row 300. I Am sure I could repeat the code
for each of the 300 rows but I bet there is a better way.

Private Sub Worksheet_Calculate()
Me.Range("A2").Value = Me.Range("D2")
End Sub




Patrick Simonds

Repeat code over 300 rows
 
Sorry

Me.Range("A2").Value = Me.Range("D2")
A3 D3
A4 A5
A6 A6

All the way down to row 300



"Tim Williams" <saxifrax at pacbell dot net wrote in message
...
for i=2 to 300
me.cells(i,1).value=me.cells(i,4).value
next i

though it's not clear from your post whether A3 should equal D2 or D3....


Tim



"Patrick Simonds" wrote in message
...
How can I alter this code so that if performs the function not just on
row 2 but all the way down through row 300. I Am sure I could repeat the
code for each of the 300 rows but I bet there is a better way.

Private Sub Worksheet_Calculate()
Me.Range("A2").Value = Me.Range("D2")
End Sub






Patrick Simonds

Repeat code over 300 rows
 
Having tried your cod, it does exactly what I need. Thank you


"Tim Williams" <saxifrax at pacbell dot net wrote in message
...
for i=2 to 300
me.cells(i,1).value=me.cells(i,4).value
next i

though it's not clear from your post whether A3 should equal D2 or D3....


Tim



"Patrick Simonds" wrote in message
...
How can I alter this code so that if performs the function not just on
row 2 but all the way down through row 300. I Am sure I could repeat the
code for each of the 300 rows but I bet there is a better way.

Private Sub Worksheet_Calculate()
Me.Range("A2").Value = Me.Range("D2")
End Sub






Peter T

Repeat code over 300 rows
 
Hi Patrick,

Me.Range("A2:A301").Value = Me.Range("D2:D301").Value

The Me qualifier assumes code is in a Worksheet module.

Regards,
Peter T

"Patrick Simonds" wrote in message
...
How can I alter this code so that if performs the function not just on row

2
but all the way down through row 300. I Am sure I could repeat the code

for
each of the 300 rows but I bet there is a better way.

Private Sub Worksheet_Calculate()
Me.Range("A2").Value = Me.Range("D2")
End Sub






All times are GMT +1. The time now is 12:37 AM.

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