Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Repeat Code To Next ows Containing Data

Status
Not open for further replies.

APElliott

Technical User
Jul 9, 2002
165
GB
Hello,

Can i repeat the code below to run for rows 2 to 600 instead of retyping the code 600 times?


Range("c2").Select
Application.CutCopyMode = False
ActiveCell.FormulaR1C1 = "0"
Range("i2").Select
Selection.Copy
Range("j2").Select
Selection.PasteSpecial Paste:=xlValues
Range("h2").Select
Application.CutCopyMode = False
Selection.Copy
Range("c2").Select
Selection.PasteSpecial Paste:=xlValues

Cheers

Andrew
 
Would this work ?
Probably more effective ways then even this but give you an idea of a For Loop and using a variable to hold a Row Number.

Sub Sample()
Dim R As Long
'Loop till R = 600
For R = 2 To 600
'Cells(RowNumber,ColNumber)
Cells(R, 3).FormulaR1C1 = "0"
Cells(R, 10).Value = Cells(R, 9).Value
Cells(R, 3).Value = Cells(R, 8).Value
Next R
End Sub
 
Andrew,

The following sub routine will loop through a named range rng and copy the contents of each cell to the cell next to it.

Code:
Public Sub Copy_Range()
    
    Dim rng As Range
    Dim cell As Object
    Set rng = ActiveSheet.Range("g3:g33")
    
    For Each cell In rng
        cell.Offset(0, 1).Value = cell.Value
    Next cell
End Sub

with some modification this could do what you are looking for.

Tom
 
Cheers Kevin,

Just done your code - i'm runnin round the room!

Lots faster!!!!

Cheers Tom - much appreciated!

Thanks

Andrew
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top