LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 983
Default Optimizing Code

I have a function that I need to run very frequently for an end user
application that is already slow enough. What I need to do is to add up the
values in every second column to the right of a given cell. I was hoping that
someone could look at this code and tell me if there is any way to squeek a
little more speed out of it...

Option Explicit

Sub test()
Dim x As Double

x = AddAlternatingColumns(Sheet2, Sheet2.Range("B2"))
MsgBox x
End Sub

Public Function AddAlternatingColumns(ByVal wks As Worksheet, ByVal
rngTarget As Range) As Double
Dim dblReturnValue As Double
Dim intLastColumn As Integer

intLastColumn = wks.Range("A1").SpecialCells(xlCellTypeLastCell).C olumn
Do While rngTarget.Column < intLastColumn
Set rngTarget = rngTarget.Offset(0, 2)
dblReturnValue = dblReturnValue + rngTarget.Value
Loop
AddAlternatingColumns = dblReturnValue
End Function

--
Thanks In Advance...

Jim Thomlinson
 
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
MapPoint Optimizing mak Excel Discussion (Misc queries) 0 August 17th 05 09:30 PM
optimizing code? (hide) Johan Johansson Excel Programming 2 November 22nd 04 06:55 PM
optimizing a macro The Grinch[_11_] Excel Programming 2 August 4th 04 09:55 AM
optimizing a lookup Yakimo[_2_] Excel Programming 1 May 28th 04 04:02 PM
Optimizing in VB Phil Excel Programming 1 August 8th 03 05:18 PM


All times are GMT +1. The time now is 10:17 AM.

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

About Us

"It's about Microsoft Excel"