Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.misc
jaccker
 
Posts: n/a
Default an interesting Excel question


I have a question about the using of Excel and VBA.

Let’s say in cell A1 and A2, I input 1 and 2. Then I input formula
“=SUM(A1+A2)” into cell A3.

I would like to write a VBA code to have the following functionality:

Once I change the formula in A3, let’s say I input 4 to cell A3, the
color of the cell A3 should be changed.
Once I double click the changed cell A3, it should recover to the
formula “=SUM(A1+A2)”.

Anybody could help me out to solve the problem?

Thank you


--
jaccker
------------------------------------------------------------------------
jaccker's Profile: http://www.excelforum.com/member.php...o&userid=33116
View this thread: http://www.excelforum.com/showthread...hreadid=529223

  #2   Report Post  
Posted to microsoft.public.excel.misc
gjcase
 
Posts: n/a
Default an interesting Excel question


Take a look at

http://www.cpearson.com/excel/events.htm

For a discussion on worksheet events.

---GJC


--
gjcase
------------------------------------------------------------------------
gjcase's Profile: http://www.excelforum.com/member.php...o&userid=26061
View this thread: http://www.excelforum.com/showthread...hreadid=529223

  #3   Report Post  
Posted to microsoft.public.excel.misc
Bob Phillips
 
Posts: n/a
Default an interesting Excel question

This might work for you

Dim prevVal
Const WS_RANGE As String = "A3"

'-----------------------------------------------------------------
Private Sub Worksheet_BeforeDoubleClick(ByVal Target As Range, Cancel As
Boolean)
'-----------------------------------------------------------------
If Not Intersect(Target, Me.Range(WS_RANGE)) Is Nothing Then
With Target
If .Interior.ColorIndex = 3 Then
.Formula = prevVal
.Interior.ColorIndex = xlColorIndexNone
End If
End With
End If

End Sub

'-----------------------------------------------------------------
Private Sub Worksheet_Change(ByVal Target As Range)
'-----------------------------------------------------------------

On Error GoTo ws_exit:
Application.EnableEvents = False
If Not Intersect(Target, Me.Range(WS_RANGE)) Is Nothing Then
With Target
.Interior.ColorIndex = 3 'red
End With
End If

ws_exit:
Application.EnableEvents = True
End Sub

'-----------------------------------------------------------------
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
'-----------------------------------------------------------------
If Not Intersect(Target, Me.Range(WS_RANGE)) Is Nothing Then
With Target
If .HasFormula Then
prevVal = .Formula
End If
End With
End If
End Sub

'This is worksheet event code, which means that it needs to be
'placed in the appropriate worksheet code module, not a standard
'code module. To do this, right-click on the sheet tab, select
'the View Code option from the menu, and paste the code in.





--
HTH

Bob Phillips

(remove nothere from email address if mailing direct)

"jaccker" wrote in
message ...

I have a question about the using of Excel and VBA.

Let's say in cell A1 and A2, I input 1 and 2. Then I input formula
"=SUM(A1+A2)" into cell A3.

I would like to write a VBA code to have the following functionality:

Once I change the formula in A3, let's say I input 4 to cell A3, the
color of the cell A3 should be changed.
Once I double click the changed cell A3, it should recover to the
formula "=SUM(A1+A2)".

Anybody could help me out to solve the problem?

Thank you


--
jaccker
------------------------------------------------------------------------
jaccker's Profile:

http://www.excelforum.com/member.php...o&userid=33116
View this thread: http://www.excelforum.com/showthread...hreadid=529223



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


Similar Threads
Thread Thread Starter Forum Replies Last Post
Excel files in separate program windows Jason Dove Excel Discussion (Misc queries) 27 October 24th 08 07:58 PM
When Excel workbook starts I want to ask a question first Steve Excel Discussion (Misc queries) 5 October 4th 05 02:52 AM
Excel Range Value issue (Excel 97 Vs Excel 2003) Keeno Excel Discussion (Misc queries) 2 June 13th 05 02:01 PM
eXceL 2003 - list or combo box question David Gerstman Excel Discussion (Misc queries) 2 May 23rd 05 03:58 PM
Statistical Excel Function Question within Excel 2000... Drew H Excel Worksheet Functions 3 October 31st 04 06:55 PM


All times are GMT +1. The time now is 02:33 PM.

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

About Us

"It's about Microsoft Excel"