Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
Les Les is offline
external usenet poster
 
Posts: 240
Default Advice on code

Hello all, i have to loop down a sheet in column "L" and for each cell i need
to calculate "=(J12-H12)/30.5". Is it better/Quicker to do the calculation in
VBA and then insert the result in applicable row in in column "L", or is it
better to loop down and put a calculation in each cell ?

--
Les
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 638
Default Advice on code

On May 19, 10:31*am, Les wrote:
Hello all, i have to loop down a sheet in column "L" and for each cell i need
to calculate "=(J12-H12)/30.5". Is it better/Quicker to do the calculation in
VBA and then insert the result in applicable row in in column "L", or is it
better to loop down and put a calculation in each cell ?

--
Les


The speed of the calculation would depend on the amount of data in
your worksheet. If you need the values in L to be dynamic once they
are entered, then you will need to leave the formula intact. If you
don't need them to be dynamic, then you can just place the calculated
value in the cell.

This will place the formula in L12 and autofill down to the last used
row in column A/

Sub Example4()
Dim lRow As Long
lRow = Cells(Rows.Count, "A").End(xlUp).Row
Range("L12").Formula = "=(J12-H12)/30.5"
Range("L12").AutoFill Destination:=Range("L12:L" & lRow)
End Sub

This is one way of looping through column L to the last used row in
column A and place the calculated value.

Sub Example5()
Dim lRow As Long, i As Long
lRow = Cells(Rows.Count, "A").End(xlUp).Row
For i = 12 To lRow
Cells(i, "L").Value = _
(Range("J" & i).Value - Range("H" & i).Value) / 30.5
Next i
End Sub
  #3   Report Post  
Posted to microsoft.public.excel.programming
Les Les is offline
external usenet poster
 
Posts: 240
Default Advice on code

Thanks a million JW.

Your help is much appreciated.
--
Les


"JW" wrote:

On May 19, 10:31 am, Les wrote:
Hello all, i have to loop down a sheet in column "L" and for each cell i need
to calculate "=(J12-H12)/30.5". Is it better/Quicker to do the calculation in
VBA and then insert the result in applicable row in in column "L", or is it
better to loop down and put a calculation in each cell ?

--
Les


The speed of the calculation would depend on the amount of data in
your worksheet. If you need the values in L to be dynamic once they
are entered, then you will need to leave the formula intact. If you
don't need them to be dynamic, then you can just place the calculated
value in the cell.

This will place the formula in L12 and autofill down to the last used
row in column A/

Sub Example4()
Dim lRow As Long
lRow = Cells(Rows.Count, "A").End(xlUp).Row
Range("L12").Formula = "=(J12-H12)/30.5"
Range("L12").AutoFill Destination:=Range("L12:L" & lRow)
End Sub

This is one way of looping through column L to the last used row in
column A and place the calculated value.

Sub Example5()
Dim lRow As Long, i As Long
lRow = Cells(Rows.Count, "A").End(xlUp).Row
For i = 12 To lRow
Cells(i, "L").Value = _
(Range("J" & i).Value - Range("H" & i).Value) / 30.5
Next i
End Sub

Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Advice on code Greg[_27_] Excel Programming 0 May 10th 06 04:48 PM
Need some advice on the following code Dean[_9_] Excel Programming 3 March 3rd 06 01:01 AM
Little more advice on this code Greg B Excel Discussion (Misc queries) 3 September 3rd 05 05:31 AM
Little more advice on this code Greg B[_5_] Excel Programming 3 September 3rd 05 05:31 AM
Code advice please... BruceJ[_2_] Excel Programming 1 November 13th 03 06:44 PM


All times are GMT +1. The time now is 08:57 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"