View Single Post
  #7   Report Post  
Posted to microsoft.public.excel.programming
JLGWhiz[_2_] JLGWhiz[_2_] is offline
external usenet poster
 
Posts: 1,565
Default looping thru rows

It runs, but as a sub. It cannot be called as a function from a worksheet
cell to return a value. It returns a #Value! error on the worksheet.


"Don Guillett" wrote in message
...
Test mine

--
Don Guillett
Microsoft MVP Excel
SalesAid Software

"JLGWhiz" wrote in message
...
First things first: A function can only return a value to a single cell,
so you need to use a Sub procedure.

Sub Z_UpdateCell()
Dim lr As Long, sh As Worksheet
Set sh = Worksheets("ListofDiff")
lr = sh.Cells(Rows.Count, 10).End(xlUp).Row
For i = 2 To lr
If Worksheets("ListofDiff").Cells(i, 10) < 0 Then
Worksheets("ListofDiff").Cells(i, 14) = -(Cells(i, 12))
Else: Worksheets("ListofDiff").Cells(i, 14) = (Cells(i, 12))
End If
Next

End Sub

See if this works for you. If you get errors post back.



"Ray" wrote in message
...
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