I created a VBA routine, which works well, that loops through a table and will calculate costs associated to a client. However, with a lot of data point, the routine can be slow (perhaps 10 - 15 min depending on the data). I am wondering if there is a more efficient way to do this?
The routine will evaluate each cell in a range (i.e. in the example at the end of this text, assuming Product A is on line 10, the routine will loop in range D10:E12) and if there is a value in that cell, will trigger a calculation (for example, if the cell currently evaluated is D10, the calculation would be 200 / 600 * $10 000).
The range can be quite huge and there is not always a lot of data in the range. What would be the most efficient way to loop through the range?
One possible way to accelerate the routine would be to simulate the "end" and "right arrow" to select the next available data point (assuming the 'looping' is from column D and E of line 10, then column D and E of line 11, and so on).
Apart from this, is there a more efficient way of coding the routine?
PS - the actual routing is much more complex than this example, it's actually a three level for..next loop that will scan ranges in three different worksheets and store the results of the calculation in another worksheet.
A....................B...................C........................... D.............. E
.......................COST..........TOTAL UNITS .....Client 1.....Client 2
Product A .....$10,000........... 600................. 200........... 400
Product B .....$25,000...........100..................100
Product C..... $75,000...........800..................................... 800
The routine will evaluate each cell in a range (i.e. in the example at the end of this text, assuming Product A is on line 10, the routine will loop in range D10:E12) and if there is a value in that cell, will trigger a calculation (for example, if the cell currently evaluated is D10, the calculation would be 200 / 600 * $10 000).
The range can be quite huge and there is not always a lot of data in the range. What would be the most efficient way to loop through the range?
One possible way to accelerate the routine would be to simulate the "end" and "right arrow" to select the next available data point (assuming the 'looping' is from column D and E of line 10, then column D and E of line 11, and so on).
Apart from this, is there a more efficient way of coding the routine?
PS - the actual routing is much more complex than this example, it's actually a three level for..next loop that will scan ranges in three different worksheets and store the results of the calculation in another worksheet.
A....................B...................C........................... D.............. E
.......................COST..........TOTAL UNITS .....Client 1.....Client 2
Product A .....$10,000........... 600................. 200........... 400
Product B .....$25,000...........100..................100
Product C..... $75,000...........800..................................... 800