View Single Post
  #10   Report Post  
Posted to microsoft.public.excel.programming
RaY RaY is offline
external usenet poster
 
Posts: 164
Default looping thru rows

Hi Ryan,
Thanks for your help. Sorry for taking so long to check this but I could not
find my post until now. Both of your codes worked well. many thanks, Ray

"Ryan H" wrote:

I change your code a bit.

1.) Since you are not returning any kind of data it is not neccessary to
use a Function. So I changed it to a Sub. No big deal though.

2.) I changed your cell references from Cells(2,10) to Cells(2, "J"). I
don't like to label columns by number because it can be hard to debug.

3.) When looping thru a range of cells (or objects) it is recommended to
use the For Each...Next Loop instead of Do...Loop or For...Next Loop. But
since you wanted the Do Until that is what I gave you.

4.) Give this code a try. Hope it helps! If so, let me know, click "YES"
below.

Sub Z_UpdateCell()

Dim LastRow As Long
Dim i As Long

With Sheets("ListofDiff")
LastRow = .Cells(Rows.Count, "J").End(xlUp).Row

i = 2
Do Until i LastRow
If .Cells(i, "J") < 0 Then
.Cells(i, "N") = -(.Cells(i, "L"))
Else
.Cells(i, "N") = .Cells(i, "L")
End If
i = i + 1
Loop
End With

End Sub
--
Cheers,
Ryan


"Ray" wrote:

POSTED: SEARCH - LOOPING, IN EXCEL PROGRAMMING

Hello,

I am trying convert a value of one column (col 12 is value) to negative if
the value in another column (col 10 is cs qty) is negative. The result would
update to column 14 as - or + value.

The function below works but I cant get it to loop thru the entire rows. The
amount of records changes daily. I am trying to loop this using do until but
I cant get it to work. Would you please show me how to get this to loop thru
the entire rows?

Function Z_UpdateCell()

If Worksheets("ListofDiff").Cells(2, 10) < 0 Then
Worksheets("ListofDiff").Cells(2, 14) = -(Cells(2, 12))
Else: Worksheets("ListofDiff").Cells(2, 14) = (Cells(2, 12))
End If


End Function

thanks, ray