Home |
Search |
Today's Posts |
#1
Posted to microsoft.public.excel.misc
|
|||
|
|||
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
Posted to microsoft.public.excel.misc
|
|||
|
|||
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
Posted to microsoft.public.excel.misc
|
|||
|
|||
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 |
Display Modes | |
|
|
Similar Threads | ||||
Thread | Forum | |||
Excel files in separate program windows | Excel Discussion (Misc queries) | |||
When Excel workbook starts I want to ask a question first | Excel Discussion (Misc queries) | |||
Excel Range Value issue (Excel 97 Vs Excel 2003) | Excel Discussion (Misc queries) | |||
eXceL 2003 - list or combo box question | Excel Discussion (Misc queries) | |||
Statistical Excel Function Question within Excel 2000... | Excel Worksheet Functions |