ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Tracking cell values...? (https://www.excelbanter.com/excel-programming/401346-tracking-cell-values.html)

Mac

Tracking cell values...?
 
I need cells linked together based on their values.
I've made up the following scenario:
select a cell (e.g. C4); invoke a macro which decremets the value in C4 by
one; another cell (e.g. A2) is somehow 'linked' to C4 and so is decremented
by one as well; that's it.
My requests a
1. Could someone please hint me to the code to do this (I'm thinking in C
and assembly, which is unfortunate for this task of course)
2. I'll have more of such links throughout my worksheet, so the perfect
solution would be to store each cell's link to its 'custom property' so that
the macro code would only read the cell clicked and from its properties see
what other cells should be afected; hope I'm making myself clear... Is this
possible somehow?

joel

Tracking cell values...?
 
All you have to do is put in the link cell =C4. You can manuals do theis on
the worksheet or do it by VBA

Range("A1") = "=C4"

or

Range("A1").formula = "=C4"

I don't see any difference with C Language, Basic, or Assembly Language. I
have over 25 years of writing code in all three languagges plus Fortran and
Pascal. I have writen assembly language proably in 10 diffferent assembly
languages.

"Mac" wrote:

I need cells linked together based on their values.
I've made up the following scenario:
select a cell (e.g. C4); invoke a macro which decremets the value in C4 by
one; another cell (e.g. A2) is somehow 'linked' to C4 and so is decremented
by one as well; that's it.
My requests a
1. Could someone please hint me to the code to do this (I'm thinking in C
and assembly, which is unfortunate for this task of course)
2. I'll have more of such links throughout my worksheet, so the perfect
solution would be to store each cell's link to its 'custom property' so that
the macro code would only read the cell clicked and from its properties see
what other cells should be afected; hope I'm making myself clear... Is this
possible somehow?


Mike H

Tracking cell values...?
 
Further to other answers to reduce the value of a cell by 1 whenever it is
selected try this. Right click the shet tab, view code and paste in

Private Sub Worksheet_Change(ByVal Target As Range)
If Target.Cells.Count 1 Or IsEmpty(Target) Then Exit Sub
If Not Intersect(Target, Range("A1,B1,C1")) Is Nothing Then 'Change to suit
If IsNumeric(Target) Then
Application.EnableEvents = False
Target = Target - 1
Application.EnableEvents = True
End If
End If
End Sub

Mike

"Mac" wrote:

I need cells linked together based on their values.
I've made up the following scenario:
select a cell (e.g. C4); invoke a macro which decremets the value in C4 by
one; another cell (e.g. A2) is somehow 'linked' to C4 and so is decremented
by one as well; that's it.
My requests a
1. Could someone please hint me to the code to do this (I'm thinking in C
and assembly, which is unfortunate for this task of course)
2. I'll have more of such links throughout my worksheet, so the perfect
solution would be to store each cell's link to its 'custom property' so that
the macro code would only read the cell clicked and from its properties see
what other cells should be afected; hope I'm making myself clear... Is this
possible somehow?


Mac

Tracking cell values...?
 
Gretát, thanks! It is not working yet, though, but I guess it's my fault in
putting the code into the worksheet...
How about the second part of my request - can you think of a way to put the
'linked cells' info somewhere into a cell (as a string, perhaps)? Is there
something like a custom property of a cell that could be used for this?

"Mike H" wrote:

Further to other answers to reduce the value of a cell by 1 whenever it is
selected try this. Right click the shet tab, view code and paste in

Private Sub Worksheet_Change(ByVal Target As Range)
If Target.Cells.Count 1 Or IsEmpty(Target) Then Exit Sub
If Not Intersect(Target, Range("A1,B1,C1")) Is Nothing Then 'Change to suit
If IsNumeric(Target) Then
Application.EnableEvents = False
Target = Target - 1
Application.EnableEvents = True
End If
End If
End Sub

Mike

"Mac" wrote:

I need cells linked together based on their values.
I've made up the following scenario:
select a cell (e.g. C4); invoke a macro which decremets the value in C4 by
one; another cell (e.g. A2) is somehow 'linked' to C4 and so is decremented
by one as well; that's it.
My requests a
1. Could someone please hint me to the code to do this (I'm thinking in C
and assembly, which is unfortunate for this task of course)
2. I'll have more of such links throughout my worksheet, so the perfect
solution would be to store each cell's link to its 'custom property' so that
the macro code would only read the cell clicked and from its properties see
what other cells should be afected; hope I'm making myself clear... Is this
possible somehow?



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

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com