Advanced cell function. is it possible

T

Tosco

Hi all,


I`m having a problem on excel and I would like to know if it`s possible
to be done without programming in VB:

Let's say i have the following:

A B C
1 100 100 1100

The formula should be on C1, and it should evaluate to:

Everytime cells A1 and B1 have the same value, C1 = A1 + 1000

If B1 for example change to 200, C1 shoulb stay 1100, until A1 changes
to 200 also, when C1 should change to 1200.

i'll try to do some simulation to make it clear:

A B C
1 100 100 1100

A B C
1 200 100 1100

A B C
1 300 100 1100

A B C
1 300 300 1300

A B C
1 300 500 1500

Or, in other words, C1 should be equal to 1000 + the value of A1 or B1
on the last time they were equal.

Thanks in advance.
 
M

Mike

I would be delighted to be told I'm incorrect by a more knowledgable user but
I think you are going to struggle with this without resorting to VB. I can
see no way of retaining the old vlaues of A1 and B1 without doing so.

If you want a VB solution please post again and check that I have corrected
your logic correctly below.

Mike
 
G

Gustavo

thanbks for your promptly repply.

Your answer was just what i wasen't expecting to have, but if thats the
only way, if you can post me a sample function in Vb that does it, it
would be great.

My main concern in not using Vb is the efficiency of it, as i'm going
to be using this formula in hundreds of cells, but if it's the only
way..

Can i use the value of the cell in my function and just change it if
the 2 others are different?

thanks again
 
E

Elkar

Actually, I'd recommend a VB solution, but by allowing a circular reference,
this can be done.

Under TOOLS-->OPTIONS-->CALCULATION Tab, check the box marked "Iterations"
and change "Maximum Interations" to 1.

Now, in C1, use this formula:

=IF(A1=B1,A1+1000,C1)

HTH,
Elkar
 
G

Gustavo

Thanks again.

What should be the downside for your solution? just the goal seek will
not work?

Thsi worksheet uses RTD data feeds. Will it still work or i'll have
some problems?

Thanks
 
J

Jop Duyvendak

Tosco, Can you reconsider your example? I'm confused about the last line of
your example: A1 = 300, B1=500 and C1 = 1500 . Shouldn't that be C1=1300???

And then, how do you want this to work. I'm unclear what you mean with 'the
last time they were equal..." Are A1 and B1 over time steadily rising in
value and you want C1 to rise with it in a step-wise manner? So the sheet
should somehow remember what the previous values were?
 
E

Elkar

There are a couple problems that may arise from turning on Iterations. First
off, other formulas in your workbook are now allowed to use ciruclar
references as well. This is a minor problem, but may make catching errors
more difficult, especially in large/complex workbooks.

But, the main problem to look out for, is that the Iterations setting is
applied to all workbooks open in the same instance of Excel. So, if you set
Iterations on one workbook, it is applied to all other workbooks that may be
open. Same with turning off Iterations. And, most annoyingly, if you open
multiple workbooks, the Iterations setting of the first workbook opened will
be applied to each subsequently opened workbook, regardless of how that
workbook was saved.

I'm not saying you shouldn't use this, but just keep these things in mind.
Elkar
 
D

Dave F

Interesting solution to use iteration. Note also that you may see a
performance degradation with circular references, since the workbook will
recalculate entirely every time a change is made to it.

Dave
 
M

Mike

Sorry somewhat late here's a VB solution

Private Sub Workbook_SheetChange(ByVal Sh As Object, ByVal Target As Range)
If Intersect(Target, Range("A1:b1")) Is Nothing Then
Exit Sub
Else
x = Worksheets("Sheet1").Cells(1, 1).Value
y = Worksheets("Sheet1").Cells(1, 2).Value
If x = y Then
Worksheets("Sheet1").Cells(1, 3).Value = x + y + 1000
End If
End If

End Sub
 
M

Mike

got ot wrong in the end it should be A1+1000 qhen A1=B1. Try this

Private Sub Workbook_SheetChange(ByVal Sh As Object, ByVal Target As Range)
If Intersect(Target, Range("A1:b1")) Is Nothing Then
Exit Sub
Else
x = Worksheets("Sheet1").Cells(1, 1).Value
y = Worksheets("Sheet1").Cells(1, 2).Value
If x = y Then
Worksheets("Sheet1").Cells(1, 3).Value = x + 1000
End If
End If

End Sub
 
G

Gustavo

Mike,


You're right. The last line of my sample was worng. The correct value
should be 1300.

A1 and B1 are rising over the tima, and i want C1 to rise together the
way i've shown in my sample.

thanks for your VB solution, but maybe i wasen't clear in my question,
as there are going to be more than a hundred rows that should behave
the same way, and as the worksheet is feed with financial market data,
and change a lot, a don't think the solution using the change event
should be the best for me. I was thinking in develop a function in VB
and use it. don't you think this way i would have a better
performance?

Considering just the performance and that i'm going to have more than
a hundred of this calculation on my worksheet, what should be the best
solution?

Circular reference, the change event of the worksheet or a worksheet
function developed in vb?


Thanks again.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top