View Single Post
  #5   Report Post  
Posted to microsoft.public.excel.programming
Gary Keramidas Gary Keramidas is offline
external usenet poster
 
Posts: 2,494
Default Is there a faster way to loop thru cells

if i had to guess, i'd say mine was faster. fraction of a second? but i'm not
sure. i've used both.

--


Gary


"Mike" wrote in message
...
Thanks Gary
While I was waiting i was trying this which was faster then the loop i posted
But for speed how does this compare to what you suggest
Dim rng As Excel.Range = xlApp.Range("G5")
xlApp.Range("G5").Formula = "=(E5-D5)*F5"
rng.AutoFill(xlApp.Range("G5:G" & lastRow),
Excel.XlAutoFillType.xlFillCopy)

"Gary Keramidas" wrote:

here's the code i forgot to post

Sub test()
Dim lastrow As Long
Dim ws As Worksheet
Set ws = Worksheets("Sheet1")
lastrow = ws.Cells(Rows.Count, "D").End(xlUp).Row
With ws
.Range("G5:G" & lastrow).Formula = "=(" & .Range("E5").Address(0, 0)
& _
"-" & .Range("D5").Address(0, 0) & ")*" & .Range("F5").Address(0,
0)
End With
End Sub


--


Gary


"Mike" wrote in message
...
Where lastRow maybe +/- 25000
For i = 5 To lastRow
xlApp.Cells(i, "G").value = _
(xlApp.Cells(i, "E").value - xlApp.Cells(i, "D").value) _
* xlApp.Cells(i, "F").value
Next