Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
Tom Tom is offline
external usenet poster
 
Posts: 6
Default Is This Possible?

Hi,

I've recently started writing functions in Excel which I then call from
cells to perform calculations etc. However, I am aware that a function
cannot alter the value of *another* cell. What I want to do is this :

<Cell 1 is usually empty.
When <Cell 1 changes from empty to any other value, take a snapshot of
<Cell 2 (which updates constantly) and copy it into <Cell 3.
<Cell 2 will then continue to update as usual, whilst <Cell 3 will contain
a static value.
Then when <Cell 1 becomes empty again, erase <Cell 3 and that's it.
Then keep repeating this whole process as long as the spreadsheet is open.

The concept sounds simple enough and I'm sure it must be possible but I
can't for the life of me figure out how! All I've been using so far is
functions, which take arguments and return values. Any help appreciated!

Many thanks,

Tom


  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 279
Default Is This Possible?

VBA functions can change the value of "another cell" they really can do just
about anything.

However what you want here is code in your Workbook_SheetChange event
From VBE choose thisworkbook
pulldown Sheetchange
insert code

Private Sub Workbook_SheetChange(ByVal Sh As Object, ByVal Target As Range)
dim myTargetCellOne as range
dim myTargetCellTwo as range
dim myTargetCellThree as range

set myTargetCellOne = 'cell1 address here
set myTargetCellTwo = 'cell2 address here
set myTargetCellThree = 'cell3 address here

If Target = myTargetCellOne Then
If myTargetCellOne.value = "" Then
myTargetCellThree.clearcontents
Exit Sub
Else myTargetCellThree.value = myTargetCellTwo.value
end if
end if

End Sub

"Tom" wrote:

Hi,

I've recently started writing functions in Excel which I then call from
cells to perform calculations etc. However, I am aware that a function
cannot alter the value of *another* cell. What I want to do is this :

<Cell 1 is usually empty.
When <Cell 1 changes from empty to any other value, take a snapshot of
<Cell 2 (which updates constantly) and copy it into <Cell 3.
<Cell 2 will then continue to update as usual, whilst <Cell 3 will contain
a static value.
Then when <Cell 1 becomes empty again, erase <Cell 3 and that's it.
Then keep repeating this whole process as long as the spreadsheet is open.

The concept sounds simple enough and I'm sure it must be possible but I
can't for the life of me figure out how! All I've been using so far is
functions, which take arguments and return values. Any help appreciated!

Many thanks,

Tom



  #3   Report Post  
Posted to microsoft.public.excel.programming
Tom Tom is offline
external usenet poster
 
Posts: 6
Default Is This Possible?

That's great, thankyou so much. Actually I had to do a bit of hunting
around as myTargetCellOne is actually updated via DDE link, not manually.
But I found Workbook_SheetCalculate which works very well. I love this
event stuff!

Tom

"Vacation's Over" wrote in message
...
VBA functions can change the value of "another cell" they really can do
just
about anything.

However what you want here is code in your Workbook_SheetChange event
From VBE choose thisworkbook
pulldown Sheetchange
insert code

Private Sub Workbook_SheetChange(ByVal Sh As Object, ByVal Target As
Range)
dim myTargetCellOne as range
dim myTargetCellTwo as range
dim myTargetCellThree as range

set myTargetCellOne = 'cell1 address here
set myTargetCellTwo = 'cell2 address here
set myTargetCellThree = 'cell3 address here

If Target = myTargetCellOne Then
If myTargetCellOne.value = "" Then
myTargetCellThree.clearcontents
Exit Sub
Else myTargetCellThree.value = myTargetCellTwo.value
end if
end if

End Sub

"Tom" wrote:

Hi,

I've recently started writing functions in Excel which I then call from
cells to perform calculations etc. However, I am aware that a function
cannot alter the value of *another* cell. What I want to do is this :

<Cell 1 is usually empty.
When <Cell 1 changes from empty to any other value, take a snapshot of
<Cell 2 (which updates constantly) and copy it into <Cell 3.
<Cell 2 will then continue to update as usual, whilst <Cell 3 will
contain
a static value.
Then when <Cell 1 becomes empty again, erase <Cell 3 and that's it.
Then keep repeating this whole process as long as the spreadsheet is
open.

The concept sounds simple enough and I'm sure it must be possible but I
can't for the life of me figure out how! All I've been using so far is
functions, which take arguments and return values. Any help appreciated!

Many thanks,

Tom





  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default Is This Possible?

What causes cell1 to change?

--
Regards,
Tom Ogilvy


"Tom" wrote in message
...
Hi,

I've recently started writing functions in Excel which I then call from
cells to perform calculations etc. However, I am aware that a function
cannot alter the value of *another* cell. What I want to do is this :

<Cell 1 is usually empty.
When <Cell 1 changes from empty to any other value, take a snapshot of
<Cell 2 (which updates constantly) and copy it into <Cell 3.
<Cell 2 will then continue to update as usual, whilst <Cell 3 will

contain
a static value.
Then when <Cell 1 becomes empty again, erase <Cell 3 and that's it.
Then keep repeating this whole process as long as the spreadsheet is open.

The concept sounds simple enough and I'm sure it must be possible but I
can't for the life of me figure out how! All I've been using so far is
functions, which take arguments and return values. Any help appreciated!

Many thanks,

Tom




Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



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

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"