ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Stepping through a column using FOR/NEXT (https://www.excelbanter.com/excel-programming/284190-stepping-through-column-using-next.html)

Joe Mathis

Stepping through a column using FOR/NEXT
 
Hello

I need to step through each cell of a particular column, check the contents to the previous cell, and then preform an action based on the outcome. Below is my code. Please help if you can

Thanks, Jo

With Worksheets("Source Data"
For i = 2 To .Range("e").Rows.Coun

If .Range("E" + i) < .Range("E" + (i - 1)) The

Range("e" + i).Selec
Selection.Cop
Worksheets("Gap").Range("b11").End(xlDown).Offset( 1, 0).Selec
Selection.PasteSpecial Paste:=xlPasteValue

.....etc

End I
Next i

Colo

Stepping through a column using FOR/NEXT
 
Hi Joe, :)

here is a sample code for you.
You can specify a range like this. And don't need SELECT a cell for copy and
paste, just use Value property.
Hope it works as intended.

With Worksheets("Source Data")
For i = 2 To .Columns("E").Rows.Count
If .Range("E" & i).Value < .Range("E" & (i - 1)).Value Then
Worksheets("Gap").Range("b11").End(xlDown).Offset( 1,
0).Value = _
Range("E" & i).Value
' .....etc.
End If
Next i
End With


--
Kind Regards
Colo
/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/
Colo of 'The Road of The Cell Masters' :)

URL:http://www.interq.or.jp/sun/puremis/...astersLink.htm


/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/


"Joe Mathis" wrote in message
...
Hello,

I need to step through each cell of a particular column, check the

contents to the previous cell, and then preform an action based on the
outcome. Below is my code. Please help if you can.

Thanks, Joe

With Worksheets("Source Data")
For i = 2 To .Range("e").Rows.Count

If .Range("E" + i) < .Range("E" + (i - 1)) Then

Range("e" + i).Select
Selection.Copy
Worksheets("Gap").Range("b11").End(xlDown).Offset( 1, 0).Select
Selection.PasteSpecial Paste:=xlPasteValues

.....etc.

End If
Next i




All times are GMT +1. The time now is 12:06 PM.

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