Optimization For An UDF
Oct 6, 2008
Optimize the code below to perform a search function for two variables. Right now it takes a while to execute as it goes through each cell row by row, column by column. It would be nice to optimize it to function a little faster (make that alot faster) . I realize my coding methods are not all best practice habits, so let me know your thoughts, workarounds or adjustments.
In its basic form the code pasted in below is being used to locate data at the intersection of a given row and column. And this data can lie anywhere within this array, unsorted.
Where the Row to search contains a team members name (Derek, John, etc.) D3:D50 and dates in columns Q3 to IU94.
My spreadsheet has a data page with a list of team member names in D3 to D50, and a listing of dates running accross Q3 to IU94. Each members name may appear muliple times through out D3:D50.
So for instance "Derek" (cell D6) worked 40 hours (cell Q6) the week of 9/1/08, it is the 40 that I want returned to a summary page and since the name Derek may show up more than once down the list I want to return all occurances where a date and name instersect on my summary sheet.
[/quote]
Below is my code which is currently used to lookup team member name "Lookup_Value1" for a given date "Lookup_Value2), it indexes the date column to search for data.
Function LOOKUP2(Lookup_Value1 As Variant, Lookup_Value2 As Variant, TABLE_ARRAY As Range)
Dim nRow As Long
Dim nCol As Long
nRow = 0
nCol = 0
With TABLE_ARRAY..............
View 23 Replies
Aug 13, 2008
Can anyone recommend a good source for tips on optimizing VBA code? I'm working on
an application that reads and interprets large text files (3500 lines) and starting to think
about the efficiency of the code inside my read loop.
For example I'm wondering how Excel actually implements access to cells internally. Is a
cell just a variable or part of an array?
If I do something like: range("A1").value = range("A1").value + 1 inside a loop is there a
performance penalty compared with saying: count = count + 1 and then writing this to a
cell outside the loop, eg: range("A1").value = count ?
View 9 Replies
View Related
Feb 16, 2010
I use a lot the function “Find” in Excel but the problem is that it takes a lot of time, so I’m searching for another function or code that can be faster than that, the Worksheets that I use in Excel contain thousands of sheets so it takes hours to execute the Macro.
View 10 Replies
View Related
Dec 19, 2009
Have an optimization question for you. I'm starting to try to optimize my macros and I've heard/read it's best to not activate or select anything. - I assumed that meant it would be more efficient to run code without it.
I have a loop I run through about 600 times that takes .75 to .85 seconds to run through with the following piece:
View 5 Replies
View Related
Jul 31, 2012
Let me first quickly describe the workbook setup. I have a main workbook ("Fees") that acts as a master list for every employee's clients' account numbers. Every month, 30+ workbooks get downloaded from 3rd parties that have the client account numbers, as well as their current account value.
My macro- Loops through every employee's worksheet within the Fees workbook, and loops through every account number. It then compares the account to every account in every other open workbook. Upon a match, it pulls the account value back into the main workbook. After it finishes looping the Fees workbook, it starts to loop every open workbook, and checks every account value against every account in the Fees workbook. If it doesn't find a match, it prints the value on a Missed worksheet within the Fees workbook.
The situation- I know for a fact this a verrry slow way to go about what I need to accomplish. I am very new to writing code, and gladly can take the extra minutes to let the code execute to know 100% nothing was missed. Going forward, I would like to start trimming execution time without jeopardizing the 100% accuracy of my slow macro.
The question- Based on how I execute my loops, what is likely to trim the most time for the range lookups? I have no practical experience with Vlookup, but I understand that is a possibility I should look into. I'm vaguely familiar with Match, and arrays, and I believe they could also trim time. I also realize there are probably at least 15 other ways to go about it I am not even aware of.
View 9 Replies
View Related
Apr 19, 2006
I have 4 Loans of various interest rates, balances, and minimum payments.
Assuming I have a certain amount of money to pay out each month, how can I minimize the total amount I pay over the lifetime of the loans?
Given:
Total Monthly payment: M
Interest Rate for each loan: R1, R2, R3, R4
Initial Principal for each Loan: P1, P2, P3, P4
Minimum Monthly Payment: Min1, Min2, Min3, Min4
Each month, how should I distribute M over the 4 loans?
View 9 Replies
View Related
Nov 7, 2009
I am running Win XP and Excel 2003.
I have a macro I found here on the boards written by Lenze to delete an entire row based on what is found in column A. I would like to delete any row where Col. B contains 10 or less characters and I have modified it to do so (or at least I think it does). My problem is that it takes about 12 minutes to run the macro (I have about 50k lines to run through). I was wondering if this is the fastest method or if it examines things other than just column B.
Sub Test()
Dim i As Long
LR = Cells(Rows.Count, "B").End(xlUp).Row
For i = LR To 2 Step -1
If Len(Cells(i, "B")) < 11 Then Cells(i, "B").EntireRow.Delete
Next i
End Sub
After this runs, I am left with Columns A to somewhere around AH. The columns are generally in the format of text followed by a numeric column. An individual text column has the same name through all of the rows. The numeric columns have varied values whether negative or positive.
Ideally what I would like: If a given cell (ie. C2) in Row 2 is numeric, then copy the cell to the left (ie. B2) into (ie. C1) and then delete Column B. I need this to work for multiple columns from B to C, skip D and E, and then from F to AG (and maybe beyond).
View 9 Replies
View Related