PC Review


Reply
Thread Tools Rate Thread

Advice on code

 
 
Les
Guest
Posts: n/a
 
      19th May 2008
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
 
Reply With Quote
 
 
 
 
JW
Guest
Posts: n/a
 
      19th May 2008
On May 19, 10:31*am, Les <L...@discussions.microsoft.com> 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 With Quote
 
Les
Guest
Posts: n/a
 
      19th May 2008
Thanks a million JW.

Your help is much appreciated.
--
Les


"JW" wrote:

> On May 19, 10:31 am, Les <L...@discussions.microsoft.com> 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 With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

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


Similar Threads
Thread Thread Starter Forum Replies Last Post
Advice on code Greg Microsoft Excel Programming 0 10th May 2006 04:48 PM
Need some advice on the following code Dean Microsoft Excel Programming 3 3rd Mar 2006 01:01 AM
Little more advice on this code Greg B Microsoft Excel Misc 3 3rd Sep 2005 05:31 AM
Need advice, help, possible code example Aaron Microsoft ADO .NET 2 21st May 2004 06:29 PM
Code advice please... BruceJ Microsoft Excel Programming 1 13th Nov 2003 06:44 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 04:32 AM.