943,917 Members | Top Members by Rank

Ad:
Sep 23rd, 2009
0

Range-objects, excel

Expand Post »
Hi guys,

I am writing (trying to write) a program in VBA for Excel 2003 and I got stuck, I need your help, please.

I have an excel range where the upmost cell is initially fixed and the downmost cell moves down as more data arrive.
In other words I have something like WorkRange = Range((1,1), (LastRow,1)).
In the range I have integers and LastValue is the value of the integer in cell (LastRow,1).
Over this range I calculate the maximum value (MaxVal) and the difference between LastValue and MaxVal.
So far it's (almost) easy, even for me.

Problem is, when the difference between LastValue and MaxVal satisfies a certain condition ( ie LastValue-MaxValue < z=constant) I need to move down the upmost cell in the WorkRange, so that it is set to coincide with the cell where the MaxVal is.
After that the program should me made to loop.
Normally the data series would be 40k rows long, but it could get 500k rows long I am afraid.

IN THEORY I have an idea of how I can solve this problem but I do not know how to do it practically with VBA.

I thought that maybe I could define the starting cell of the WorkRange as a Cell-object.
For example I could call it StartCell1. The WorkRange would then be:
WorkRange=Range(StartCell1,(LastRow,1)).
StartCell1 would be the first cell where I have data.

When condition ( LastValue-MaxValue < z) is satisfied I could create a Cell-object called LastCell1 that would be the first cell where the condition is satisfied.
I would also create a Cell-object called MaxVal1, that would be the cell where you find the maximum value in the range up to that point.
Finally I could also create a Range-object called WorkRange1=Range(StartCell1,LastCell1).

Done that I could create a new Cell-object, call it StartCell2 , and set it to have the same properties of Cell-object MaxVal1.
At that point the WorkRange would be WorkRange=Range(StartCell2,(LastRow,1)) and I could loop the program repeating the above.

Does it make sense ?
The problem is that I have no idea on how practically do this.
I am surfing through books and the web but did not find a solution so far. Can't see the shore either .... Anybody can please help ?

Thank you in advance
Frank


PS: I posted also yesterday but no replies. I hope I made my question clearer ...
Similar Threads
Reputation Points: 10
Solved Threads: 0
Newbie Poster
orsodani is offline Offline
2 posts
since Sep 2009

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in Visual Basic 4 / 5 / 6 Forum Timeline: Copy Table Mysql to MS Access
Next Thread in Visual Basic 4 / 5 / 6 Forum Timeline: Copy Table Mysql to MS Access





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC